Last active
May 30, 2018 18:42
-
-
Save mbarkhau/e4f3dde91bbb137b29973c362e2c128e to your computer and use it in GitHub Desktop.
ssh_lib_rtt_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
from __future__ import unicode_literals | |
import os | |
import sys | |
import time | |
from plumbum.machines.paramiko_machine import ParamikoMachine | |
user = sys.argv[1] | |
host = sys.argv[2] | |
pkey_path = os.path.expanduser("~/.ssh/id_rsa") | |
cmd = "echo 'hello world'" | |
paramiko_times = [] | |
with ParamikoMachine(host, user=user) as remote_host: | |
with remote_host.session() as session: | |
times = [] | |
for i in range(9): | |
t0 = time.time() | |
exit_code, stdout, stderr = session.run(cmd, retcode=None) | |
paramiko_times.append((time.time() - t0) * 1000) | |
assert stdout.strip() == "hello world" | |
from pssh.clients.native.single import SSHClient | |
psshrun_times = [] | |
client = SSHClient(host, user=user, pkey=pkey_path) | |
for i in range(7): | |
t0 = time.time() | |
res = client.run_command(cmd) | |
stdout = "\n".join(res[2]) | |
assert stdout.strip() == "hello world" | |
psshrun_times.append((time.time() - t0) * 1000) | |
psshopen_times = [] | |
psshcmd_times = [] | |
psshtotal_times = [] | |
for i in range(7): | |
t0 = time.time() | |
channel = client.open_session() | |
t1 = time.time() | |
client.execute(cmd, channel=channel) | |
stdout = "\n".join(client.read_output(channel)) | |
stderr = "\n".join(client.read_stderr(channel)) | |
client.wait_finished(channel) | |
assert stdout.strip() == "hello world" | |
psshopen_times.append((t1 - t0) * 1000) | |
psshcmd_times.append((time.time() - t1) * 1000) | |
psshtotal_times.append((time.time() - t0) * 1000) | |
def fmt_times(name, times): | |
return "{:<20} {:8.2f} {:8.2f} {:8.2f}".format( | |
name, min(times), max(times), sum(times) / len(times) | |
) | |
print(" min [ms] max [ms] avg [ms]") | |
print(fmt_times("paramiko", paramiko_times)) | |
print(fmt_times("pssh run_command", psshrun_times)) | |
print(fmt_times("pssh execute", psshtotal_times)) | |
print(fmt_times(" open", psshopen_times)) | |
print(fmt_times(" cmd", psshcmd_times)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min [ms] max [ms] avg [ms] | |
paramiko 5.60 10.73 7.46 | |
pssh run_command 24.18 69.31 56.47 | |
pssh execute 54.36 59.10 56.12 | |
open 40.79 43.24 42.19 | |
cmd 13.37 15.86 13.92 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment