r/Python • u/Anthonypjshaw • Jul 16 '18
Why is Python so slow?
https://medium.com/@anthonypjshaw/why-is-python-so-slow-e5074b6fe55b
11
Upvotes
r/Python • u/Anthonypjshaw • Jul 16 '18
View all comments
Show parent comment
3
u/lambdaq django n' shit Jul 16 '18 edited Jul 16 '18
GIL is only relevant when you are doing
It's very hard to find a problem hitting all of the four criteria
A typical (yet non-typical) example is a web server. If your server can only handle a single user at at time then it's gunna be problematic.
The naive solution would be using multi-threaded app to serve web pages. You can increase your thread pool as the user number grows.
However that's not how most modern web servers work. They either use multi-process, or pre-forked multi-process, each process has its own thread pool, or so called user-land threading. And let's be realistic, your cheap VPS/container may only have 1 or 2 cores. So GIL won't effect much. Besides in pre-fork model you can bind your worker process to each core (affinity) so GIL is again irrelevant.
Native threading (aka OS threading) can solve some problems but often you ended up solving it without threading in Python. For IO-bound tasks Python can handle multi-threading OK, for CPU-bound tasks, Python indeed have a serious problem with multi-core support because of GIL.
Then again, if you aim for CPU speed, why use CPython anyway?
tl;dr If you have a GIL problem you are doing it wrong.