【问题标题】:measure data transfer rate with 200 simultaneous users测量 200 个同时用户的数据传输率
【发布时间】:2012-07-17 22:53:18
【问题描述】:

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

是否有一些 python 或 linux 工具可以解决这个问题?或者您能推荐一种方法吗?

我看到this speedcheck code,我可以把它包装在线程中,但我不明白为什么那里的代码如此“复杂”,并且块大小一直在变化。

【问题讨论】:

  • 为什么下载一个文件需要200个线程?当您的互联网链接成为瓶颈时,更多的线程不会让它变得更快。
  • 我将线程更改为用户。我需要看看当 200 个用户同时尝试下载文件时,传输速率是多少。

标签: python linux networking performance-testing


【解决方案1】:

我最近使用Mult-Mechanize 运行一些性能测试。这很简单,而且效果很好。

【讨论】:

  • 我很熟悉。我看不到您如何查看传输率,因为它衡量交易延迟。谢谢
【解决方案2】:

不确定您说的是不是真正的专用服务器。对于流量图等,我更喜欢使用Munin。这是一个非常完整的监控应用程序,它使用 rrdtool 为您构建漂亮的图表。示例链接在 munin 网站上:full setupeth0 traffic graph

new munin 2 更加华丽,但我还没有使用它,因为它不在我的存储库中,而且我不喜欢弄乱 perl 应用程序。

【讨论】:

  • 我只需要对我自己的服务器进行简单的全面检查。我编写自己的代码。我希望它没问题。你可以在答案中看到代码。
  • @user1495181 当然没关系。虽然 munin 设置简单且功能强大。我喜欢图表。
【解决方案3】:

也许 'ab' 来自 apache ?

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 或男人ab

【讨论】:

    【解决方案4】:
    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'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-26
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多