简体   繁体   English

我应该为IOCP创建多少个线程?

[英]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. 我已经读到传递给CreateIoCompletionPort()函数的NumberOfConcurrentThreads参数的理想数是0 ,它将转换为内核数。

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. 这些因素包括存在多少其他线程,此IOCP的线程多久工作一次,导致它们阻塞,您实际拥有多少个内核等。

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. 在许多设计和现代硬件中,我发现少量线程是绰绰有余的,而且这个数目通常比内核数少得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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