0

I have read that the ideal number to pass to the NumberOfConcurrentThreads parameter of the CreateIoCompletionPort() function is 0, which will translate to the number of cores.

However, how many threads I should actually create that waits on the completion port, should it also be the same as the number of cores?

Tom
  • 1,344
  • 9
  • 27
  • 1
    If you do a lot of *other* waits (on things other than the completion port) of a non-trivial duration, then it makes sense to have extra threads so that the CPU can be fully utilized. If you never wait on anything other than the completion port, then AFAIK there is no reason to have more than one per core. I think you need to experiment to find the best balance for your particular application. (Of course for many real-world applications, one or two threads can easy handle all the traffic. It depends on the amount of load.) – Harry Johnston Mar 04 '15 at 02:53

1 Answers1

1

This question is impossible to answer with a definitive number as that number will depends on lots of other factors within the design of your code. Factors such as how many other threads are present, how often the threads for this IOCP do work which causes them to block, how many cores you actually have, etc.

My preferred approach is to make the number of threads externally configurable so that you can profile your code once it is working and tune the number of threads.

In many designs, and with modern hardware, I find that a small number of threads is more than adequate and this number is often much less than the number of cores.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92