[Python-Dev] GIL behaviour under Windows

Antoine Pitrou solipsis at pitrou.net
Wed Oct 21 14:52:40 CEST 2009


> I don't really know how this test works, so I won't claim to understand
> the results either. However, here you go:

Thanks.

Interesting results. I wonder what they would be like on a multi-core
machine. The GIL seems to behave perfectly on your setup (no performance
degradation due to concurrency, and zero latencies).

For a quick explanation of what the benchmark does:

- the "throughput" part launches N computational (CPU-bound) threads and
measures the total work done per second, and then compares the result to
the 1-thread result. It does so with three different workloads, which
have different impacts on the GIL. 100% is the most you can get on a
single-core machine. On a multi-core machine, you can get more than 100%
with the workload that explicitly releases the GIL before taxing the CPU
(bz2 compression).

- the "latency" part launches N computational threads in the background,
and the main thread listens for periodic ping messages on an UDP socket
(the ping messages themselves are emitted from a separate Python
process, so as to decouple it from the process under test). The
latencies are the measured delay between the emission of the UDP message
and the moment at which the recv() call returns in the main thread. This
aims at reproducing the situation where a thread handles IO operations
while one or several other threads perform heavy computations.

Regards

Antoine.


> C:\>systeminfo
> OS Name:                   Microsoft Windows XP Professional
> OS Version:                5.1.2600 Service Pack 3 Build 2600
> 
> C:\>c:\Python26\python.exe
> Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
> (Intel)] on win32
> 
> C:\>start /B /HIGH c:\Python26\python.exe c:\ccbench.py
> --- Throughput ---
> 
> Pi calculation (Python)
> 
> threads=1: 377 iterations/s.
> threads=2: 376 ( 99 %)
> threads=3: 380 ( 100 %)
> threads=4: 376 ( 99 %)
> 
> regular expression (C)
> 
> threads=1: 222 iterations/s.
> threads=2: 213 ( 95 %)
> threads=3: 223 ( 100 %)
> threads=4: 218 ( 97 %)
> 
> bz2 compression (C)
> 
> threads=1: 324 iterations/s.
> threads=2: 324 ( 99 %)
> threads=3: 327 ( 100 %)
> threads=4: 324 ( 100 %)
> 
> --- Latency ---
> 
> Background CPU task: Pi calculation (Python)
> 
> CPU threads=0: 0 ms. (std dev: 0 ms.)
> CPU threads=1: 0 ms. (std dev: 0 ms.)
> CPU threads=2: 0 ms. (std dev: 0 ms.)
> CPU threads=3: 0 ms. (std dev: 0 ms.)
> CPU threads=4: 0 ms. (std dev: 0 ms.)
> 
> Background CPU task: regular expression (C)
> 
> CPU threads=0: 0 ms. (std dev: 0 ms.)
> CPU threads=1: 0 ms. (std dev: 0 ms.)
> CPU threads=2: 0 ms. (std dev: 0 ms.)
> CPU threads=3: 0 ms. (std dev: 0 ms.)
> CPU threads=4: 0 ms. (std dev: 0 ms.)
> 
> Background CPU task: bz2 compression (C)
> 
> CPU threads=0: 0 ms. (std dev: 0 ms.)
> CPU threads=1: 0 ms. (std dev: 0 ms.)
> CPU threads=2: 0 ms. (std dev: 0 ms.)
> CPU threads=3: 0 ms. (std dev: 0 ms.)
> CPU threads=4: 0 ms. (std dev: 0 ms.)
> 



More information about the Python-Dev mailing list