How many threads can I create ???

Kragen Sitaker kragen at pobox.com
Wed Dec 5 05:11:22 EST 2001


Tim Roberts <timr at probo.com> writes:
> The only use for your test is to establish the limits.  Now you know the
> limit: 85.  However, that fact is not particularly useful.  It is
> counterproductive to launch an application with a hundred threads.  You
> will simply waste CPU time thrashing in the scheduler.

Only a very poor scheduler will thrash with 85 threads, 2 of which are
runnable at any given time.  It's not at all hard to use 85 or 200 or
300 threads if you're writing, say, a multithreaded web server.  At
the moment, just running a normal Linux box, I have 80 threads on my
machine, and it works fine.  (Those threads mostly living in separate
virtual memory spaces doesn't make it any easier on the scheduler.  It
makes it harder.)

Some people might argue that writing a multithreaded web server is a
stupid idea if you're planning to service 85 or 200 or 300 clients
simultaneously.  They are wrong.  While a multithreaded web server
often won't be as efficient as an event-driven single-threaded web
server, it can be a hell of a lot easier to program, and if your
program is running in the Python interpreter, your bottleneck is
unlikely to be context-switching time anyway.




More information about the Python-list mailing list