Questions about GIL and web services from a n00b

sturlamolden sturlamolden at yahoo.no
Sun Apr 17 17:49:35 CEST 2011


On Apr 17, 5:15 pm, Ian <hobso... at gmail.com> wrote:

> > 5) Even in CPython, I/O-bound processes are not slowed significantly
> > by the GIL.  It's really CPU-bound processes that are.
>
> Its ONLY when you have two or more CPU bound threads that you may have
> issues.

And when you have a CPU bound thread, it's time to find the offending
bottleneck and analyse the issue.

Often it will be a bad choise of algorithm, for example one that is
O(N**2) instead of O(N log N). If that is the case, it is time to
recode.

If algoritmic complexity is not the problem, it is time to remember
that Python gives us a 200x speed penalty over C. Moving the
offending
code to a C library might give a sufficent speed boost.

If even that does not help, we could pick a library that uses
multi-threading internally, or we could release the GIL and use
multiple threads from Python. And if the library is not thread-safe,
it is time to use multiprocessing.


Sturla



More information about the Python-list mailing list