pythonmultithreadingubuntucstringio

multi threaded cstringio is 17% slower on ubuntu 14.04


I am running the following program:

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)

on machines with exact same hardware however one running ubuntu 10.04 and the other running 14.04. I observe that it takes 1409.54 sec on 10.04 whereas it takes 1656.81 sec on 14.04 showing 17% performance degradation on 14.04. Any ideas?


Solution

  • This behavior was due to hyperthreading on 14.04. Interestingly after disabling hyper thread on my 2 core machine (and effectively running on a single hyper thread), 14.04 gave performance that was at par with that of 10.04.