当前位置:网站首页>应用软件线程数与CPU核数之间的关系
应用软件线程数与CPU核数之间的关系
2022-04-21 06:37:00 【饮水思源09】
一般说来,大家认为线程池的大小经验值应该这样设置:(其中N为CPU的个数)
- 如果是CPU密集型应用,则线程池大小设置为N+1
- 如果是IO密集型应用,则线程池大小设置为2N+1(因为io读数据或者缓存的时候,线程等待,此时如果多开线程,能有效提高cpu利用率)
如果一台服务器上只部署这一个应用并且只有这一个线程池,那么这种估算或许合理,具体还需自行测试验证。
但是,IO优化中,这样的估算公式可能更适合:
最佳线程数目 = ((线程等待时间+线程CPU时间)/线程CPU时间 )* CPU数目
因为很显然,线程等待时间所占比例越高,需要越多线程。线程CPU时间所占比例越高,需要越少线程。
下面举个例子:
比如平均每个线程CPU运行时间为0.5s,而线程等待时间(非CPU运行时间,比如IO)为1.5s,CPU核心数为8,那么根据上面这个公式估算得到:((0.5+1.5)/0.5)*8=32。这个公式进一步转化为:
最佳线程数目 = (线程等待时间与线程CPU时间之比 + 1)* CPU数目
刚刚说到的线程池大小的经验值,其实是这种公式的一种估算值。
版权声明
本文为[饮水思源09]所创,转载请带上原文链接,感谢
https://blog.csdn.net/xsfqh/article/details/119320858
边栏推荐
- 论文阅读:Cached and Confused: Web Cache Deception in the wild
- Blue Bridge Cup -- sequence sequencing problem
- BGP 邻居
- Knowledge of classes and objects
- 策略模式(2.28-3.6)
- 2020-12-21至2022-1-2:解析观察者模式
- Ms1836s, HDMI to CVBS, video converter, HDMI receiver, built-in MCU and memory
- Troubleshooting NP and OSPF
- H + background UI framework, click the button to create a new tab
- 服务器和客户端的套接字通信
猜你喜欢

DOS command kills process

2022-1-3至2022-1-16 访问者模式

Longxun series: lt8912b, lt6911c, HDMI to Mipi (CSI \ DSI), single channel mipi2 DSi bridge to LVDS / HDM, hdmi1 4 to dual port mipidsi/csi and audio data sheet

Sorting method (3) = > quick sort and merge sort

Three layer switch and router are connected to the Internet

2020-12-25

【WPF】利用Ellipse或Rectangle制作圆形进度条

Dip image smoothing

PE header file analysis

空对象模式(3.14-3.20)
随机推荐
动态规划解决0/1背包问题
Sorting method (1) = > bubble sorting, simple selection sorting
【WPF】利用RadioButton制作导航条
Sort method (2) = > insert sort
NP、OSPF 故障排除
写入数据进入磁盘文件代码示例如下:
服务器和客户端的套接字通信
Blue Bridge Cup -- conversion between hexadecimal and decimal
Signals
2020-12-24
论文阅读:Supporting Early and Scalable Discovery of Disinformation Websites
Regular Expressions
NP、OSPF虚链路
策略模式(2.28-3.6)
Sort method ----- > Hill sort, heap sort
【C#】LINQ
【计组】性能
Longxun series: lt8912b, lt6911c, HDMI to Mipi (CSI \ DSI), single channel mipi2 DSi bridge to LVDS / HDM, hdmi1 4 to dual port mipidsi/csi and audio data sheet
Files and Directories
[untitled] Guoteng GM series, gm8284dd (gm8284dr, lt8218a), gm8285c, gm7123c, lvdsttl to TTL, TTL to single LVDS, TTL digital signal to VGA