I developed the application on gae using python 2.7, the ajax call requests some data from the API, one request can take ~ 200 ms, however, when I open two browsers and make two requests in a very short time, they take more than twice , I tried to put everything in streams, but this did not work ... (this happens when the application is connected to the network, and not just on the dev server)
So, I wrote this simple test to find out if this is a problem in python in general (in case of busy waiting), here is the code and the result:
def work(): t = datetime.now() print threading.currentThread(), t i = 0 while i < 100000000: i+=1 t2 = datetime.now() print threading.currentThread(), t2, t2-t if __name__ == '__main__': print "single threaded:" t1 = threading.Thread(target=work) t1.start() t1.join() print "multi threaded:" t1 = threading.Thread(target=work) t1.start() t2 = threading.Thread(target=work) t2.start() t1.join() t2.join()
Result for mac os x, core i7 (4 cores, 8 threads), python2.7:
single threaded: <Thread(Thread-1, started 4315942912)> 2011-12-06 15:38:07.763146 <Thread(Thread-1, started 4315942912)> 2011-12-06 15:38:13.091614 0:00:05.328468 multi threaded: <Thread(Thread-2, started 4315942912)> 2011-12-06 15:38:13.091952 <Thread(Thread-3, started 4323282944)> 2011-12-06 15:38:13.102250 <Thread(Thread-3, started 4323282944)> 2011-12-06 15:38:29.221050 0:00:16.118800 <Thread(Thread-2, started 4315942912)> 2011-12-06 15:38:29.237512 0:00:16.145560
This is pretty shocking !! if one thread takes 5 seconds to do this. I thought that starting two threads at the same time would take the same time to complete both tasks, but it takes almost three times as much time. This makes the whole idea of ββstreaming useless, as it would be faster to make them consistent!
what I miss here.
Mohamed khamis
source share