【问题标题】:multi threaded cstringio is 17% slower on ubuntu 14.04多线程 cstringio 在 ubuntu 14.04 上慢 17%
【发布时间】:2015-12-02 17:57:12
【问题描述】:

我正在运行以下程序:

import cStringIO
import time
import threading

def func(tid):
    buff = 'a'*4096
    i = 0
    while (i < 40000000):
        output = cStringIO.StringIO()
        output.write(buff)
        contents = output.getvalue()
        output.close()
        i = i + 1

threads = 16
threadlist = []

start = time.time()
for tc in range(threads):
    thr = threading.Thread(target=func, args=(tc,))
    threadlist.append(thr)
    thr.start()

for thr in threadlist:
    thr.join()

end = time.time()
print "Time taken is %s" % (end - start)

在具有完全相同硬件但一台运行 ubuntu 10.04 而另一台运行 14.04 的机器上。我观察到 10.04 需要 1409.54 秒,而 14.04 需要 1656.81 秒,显示 14.04 性能下降 17%。有什么想法吗?

【问题讨论】:

  • 你试过转换成python3吗?同时对 python3 进行了重大的性能改进。还有一点,你检查过每个系统上的python版本了吗?
  • @BeowulfOF python3 不是一个选择,主要是因为它目前提供的软件包支持有限。我在两台机器上都安装并使用了相同的 python 版本,即 2.7.8。
  • 我建议使用timeit 模块再次分析程序。只是作为一个比较。

标签: python multithreading ubuntu cstringio


【解决方案1】:

此行为是由于 14.04 上的超线程。有趣的是,在我的 2 核机器上禁用超线程(并在单个超线程上有效运行)后,14.04 的性能与 10.04 相当。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 2016-12-17
    • 2011-08-24
    • 2018-07-11
    • 1970-01-01
    相关资源
    最近更新 更多