测量200个同时用户的数据传输速率



我有linux(Ubuntu)机器作为客户端。我想测量200个用户同时尝试从我的服务器下载文件时的数据传输速率。

有没有一些python或linux工具可以做到这一点?或者你能推荐一种方法吗?

我看到了这个speedcheck代码,我可以将其封装在线程中,但我不明白为什么那里的代码如此"复杂",并且块大小一直在变化。

我最近使用Mult机械化来运行一些性能测试。这相当容易,效果也很好。

不确定您所说的是不是真正的专用服务器。对于交通图等,我更喜欢使用Munin。它是一个非常完整的监控应用程序,可以使用rrdtool为您构建漂亮的图形。示例链接在munin网站上:完整设置、eth0流量图。

新的munin 2甚至更华丽,但我还没有使用它,因为它不在我的repo中,而且我不喜欢干扰perl应用程序。

也许是来自apache的"ab"?

ab -n 1000 -c 200 [http[s]://]hostname[:port]/path
-n Number of requests to perform
-c Number of multiple requests to make at a time

它有很多选择,http://httpd.apache.org/docs/2.2/programs/ab.html或man ab

import threading
import time
import urllib2
block_sz = 8192
num_threads = 1
url = "http://192.168.1.1/bigfile2"
secDownload = 30
class DownloadFileThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.u = urllib2.urlopen(url)
        self.file_size_dl = 0

    def run(self):
        while True:
            buffer = self.u.read(block_sz)
            if not buffer:
                raise 'There is nothing to read. You should have bigger file or smaller time'
            self.file_size_dl += len(buffer)

if __name__ == "__main__":
    print 'Download from url ' + url + ' use in ' + str(num_threads)  + ' to download. test time ' + str(secDownload)  
        threads = []
        for i in range(num_threads):
            downloadThread = DownloadFileThread()
            downloadThread.daemon = True
            threads.append(downloadThread)
        for i in range(num_threads):
            threads[i].start()
        time.sleep(secDownload)
        sumBytes=0
        for i in range(num_threads):
            sumBytes = sumBytes +  threads[i].file_size_dl
        print sumBytes
        print str(sumBytes/(secDownload *1000000)) + 'MBps'

最新更新