Sunday, 24 May 2009

Blogger sucks

Look at the previous post, no more explanations needed.

Unnecessary explanation: That is the HTML I fed it with.

Python threading (and the GIL)

My shiny new Quad-Core Intel i7 has brought my attention to writing software that scales on multiple processors (the OS even considers the i7 a 8-core because of the HyperThreading technology it comes with).

I like Python, I like it a lot. Still, I have to admit that its threading sucks. It doesn't at all scale to multiple processors (this is due to the GIL). So what does GIL mean anyway? It means that the Python interpreter always only executes one piece of bytecode at a time. This means, that only one thread can execute python code at a time, thus rendering threads for scaleability useless.

Here are some benchmarks on how long it takes to add a lot of numbers (distributed on n threads or processes) on my i7.















































ThreadsTime (in Seconds)Difference
121.15 -
223.17+9.56%
324.83+7.16%
425.13+1.21%
523.67-5.81%
624.90+5.21%
724.74-0.64%
825.36+2.52%
















































ProcessesTime (in Seconds)Difference
1 20.36 -
2 10.43 -48.78%
3 6.91 -33.79%
4 5.32 -22.96%
5 5.90 +11.01%
6 5.13 -13.09%
7 4.86 -5.33%
8 4.59 -5.50%