Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带Paramiko的ssh上的tail-f延迟越来越大_Python_Ssh_Paramiko_Tail - Fatal编程技术网

Python 带Paramiko的ssh上的tail-f延迟越来越大

Python 带Paramiko的ssh上的tail-f延迟越来越大,python,ssh,paramiko,tail,Python,Ssh,Paramiko,Tail,我试图检查正在运行的嵌入式系统的日志文件中是否存在错误 我已经在脚本中实现了paramiko,因为有人告诉我这是在python中使用ssh的最佳方式 现在,当我跟踪日志文件时,我看到有一个很大的延迟累积。每分钟大约增加30秒 我已经使用grep来减少打印的行数,因为我认为我收到了太多的输入,但事实并非如此 如何在运行时减少此延迟或阻止延迟增加。我想跟踪几个小时 def mkssh_conn(addr): """returns an sshconnection""" paramik

我试图检查正在运行的嵌入式系统的日志文件中是否存在错误

我已经在脚本中实现了paramiko,因为有人告诉我这是在python中使用ssh的最佳方式

现在,当我跟踪日志文件时,我看到有一个很大的延迟累积。每分钟大约增加30秒

我已经使用grep来减少打印的行数,因为我认为我收到了太多的输入,但事实并非如此

如何在运行时减少此延迟或阻止延迟增加。我想跟踪几个小时

def mkssh_conn(addr):
    """returns an sshconnection"""
    paramiko.util.logging.getLogger('paramiko').setLevel(logging.WARN)
    sshcon = paramiko.SSHClient()
    sshcon.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    sshcon.connect(addr , username, password)
    return sshcon

while True:
    BUF_SIZE = 1024
    client = mkssh_conn() #returns a paramiko.SSHClient()
    transport = client.get_transport()
    transport.set_keepalive(1)
    channel = transport.open_session()
    channel.settimeout(delta)
    channel.exec_command( 'killall tail')
    channel = transport.open_session()
    channel.settimeout(delta)
    cmd = "tail -f /log/log.log | grep -E 'error|statistics'"
    channel.exec_command(cmd)
    while transport.is_active():
        print "transport is active"
        rl, wl, xl = select.select([channel], [], [], 0.0)
        if len(rl) > 0:
            buf = channel.recv(BUF_SIZE)
            if len(buf) > 0:
                lines_to_process = LeftOver + buf
                EOL = lines_to_process.rfind("\n")
                if EOL != len(lines_to_process)-1:
                    LeftOver = lines_to_process[EOL+1:]
                    lines_to_process = lines_to_process[:EOL]
                else:
                    LeftOver = ""
                for line in lines_to_process.splitlines():
                    if "error" in line:
                        report_error(line)
                    print line
    client.close()          
我找到了一个解决方案: 似乎如果我将BUF_大小降低到256,延迟就会减少。明显地
我需要重新检查延迟在运行时是否仍然增加。

如果您使用的是高吞吐量尾管,则缓冲区大小应位于高端,以减少cpu周期(进而减少由于网络延迟而导致的总体延迟)

进一步将缓冲区大小设置为更大的数字,不应降低性能。(如果帕拉米科在低吞吐量管道中填满缓冲区后才哭)

@studioj的答案与此之间的矛盾,可能是由于paramiko的升级(现已修复)