Hacker News new | past | comments | ask | show | jobs | submit login

And load balancing matters: Google runs something like 5000 threads on systems with 16-32 cores.

Even in the most IO-bound of domains or in the case where 4.9k are sleeping, does it really make sense to ever have that many threads/core?




Sure. Modern linux can handle 100s of 1000s of threads without breaking a sweat.

See also http://paultyma.blogspot.com/2008/03/writing-java-multithrea... for an interesting (java-centric) analysis.


While the kernel certainly able to handle hundreds of thousands of threads, the main limit is memory, because by default (in libc) there is around 2M of memory allocated to the stack of each thread.

With the pthread library you can create threads with a stack size smaller than this, but this limits some aspects (think of recursion, local objects etc.) of your program.

My experiences show that it is possible to be happy with 64K stack size in an event driven program if you are careful, so you can run ~500,000 threads on 64G memory if you want to. Nevertheless you'd better design your program more clever and use only a handful of threads and put them in blocking state only when you must :)




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: