I am currently doing some I/O intensive load-testing using python. All my program does is to send HTTP requests as fast as possible to my target server.
To manage this, I use up to 20 threads as I’m essentially bound to I/O and remote server limitations.
According to ‘top’, CPython uses a peak of 130% CPU on my dual core computer.
How is that possible ? I thought the GIL prevented this ? Or is it the way Linux ‘counts’ the resources consumed by each applications ?
100 percent in top refer to a single core. On a dual-core machine, you have up to 200 per cent available.
A single single-threaded process can only make use of a single core, so it is limited to 100 percent. Since your process has several threads, nothing is stopping it from making use of both cores.
The GIL only prevents pure-Python code from being executed concurrently. Many library calls (including most I/O stuff) release the GIL, so no problem here as well. Contrary to much of the FUD on the internet, the GIL rarely reduces real-world performance, and if it does, there are usually better solutions to the problem than using threads.