[OT] This feels wrong (pthreads question)

Dave Smith dave at thesmithfam.org
Mon Jan 29 07:46:55 MST 2007


Steve wrote:
> By the way, how much overhead does threading actually introduce,
> especially in a situation where there may be hundreds or thousands of
> threads in an application?

You may get to a point where you can no longer spawn new threads, and 
pthread_create() will start to fail and you will have no recourse.

It still doesn't seem to me like you have explored select() 
sufficiently. select() will allow you to have a single thread (or even a 
small pool of threads) on the server that can handle client requests 
very quickly. If you have multiple cores, use two threads, each 
responsible for a different set of client socket descriptors. Spread the 
most active socket descriptors around evenly between the threads. That'd 
be a fun, and very efficient implementation.

If your data model is designed right, your CPU will likely never be the 
bottleneck anyway. It'll be the network.

--Dave



More information about the PLUG mailing list