码迷,mamicode.com
首页 > 其他好文 > 详细

threadpool 测试

时间:2017-06-11 00:26:33      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:use   blog   dmi   ram   pool   stdin   df -h   host   exe   

import paramiko
import threadpool
import time


def ssh(hostname,port,username,password,cmd):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname,port,username,password)
    stdin,stdout,stderr = ssh.exec_command(cmd)
    print(stdout.read().decode(utf-8))


if __name__ == __main__:
    # t0 = time.time()
    # for i in range(100):
    #     ssh(‘61.237.145.84‘,22,‘ngse_admin‘,‘tianq@6675‘,‘df -h‘)
    # print(‘时间‘,time.time() - t0)
    t1 = time.time()
    pool = threadpool.ThreadPool(10)
    l = [([1.1.1.1,22,ngse_admin,tianq@6675,df -h],None) for i in range(100)]
    requests = threadpool.makeRequests(ssh,l)
    [pool.putRequest(res) for res in requests]
    pool.wait()
    print(时间,time.time() - t1)

测试:

本机: 10个线程池 登录100台机子,用时7秒左右

          串行登录,用时56秒以上

 

threadpool 测试

标签:use   blog   dmi   ram   pool   stdin   df -h   host   exe   

原文地址:http://www.cnblogs.com/feel628/p/6980386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!