简体   繁体   中英

How many threads I should create for IOCP?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM