bokarinho
bokarinho

Reputation: 193

Optimum number of threads for maximum output

i am a bit confused about threads. If i have a file server and it is consisted of N CPUs what should be the maximum number of user mode threads in order to maximise the servers performance. Other processes do not interfere with the threads. Well my opinion is that 1 thread per cpu would be enough because if we spawn more then we would have to wait for the I/O operations to finish. If we create more threads then we will waste resources and will be blocked until other threads are finished. I am not sure if we try to read or file a file into another partition or another drive, if we can spawn a new thread for that. Can you share your opinions?

Upvotes: 1

Views: 168

Answers (1)

Daniel Pittman
Daniel Pittman

Reputation: 17232

The optimal number of threads for CPU throughput is exactly the same as the number of CPUs, for exactly the reason you name. (Though this gets more complex with the fancy "partial" cores that hyperthreading brings into the picture, but the basic rule still more or less holds.)

In the real world, if you have blocking I/O anywhere in your process then having additional threads can help overlap CPU processing and I/O processing effectively.

Upvotes: 2

Related Questions