本文介绍了根据处理器/内核创建线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于要创建的最佳线程数,我不清楚整个线程过程如何工作.我听说过/应该只创建与我的计算机正在运行的处理器数量相对应的多个线程.示例:四核处理器有4个线程,双核处理器有2个线程,等等...

那么,如果我正在运行四核计算机并创建10个线程来处理一些非常密集的计算和数据库操作,会发生什么?

我之所以这样问,是因为我实际上正在运行四核计算机,并实时进行大量的数学计算和数据库操作(插入和更新),而我的应用程序有效运行的唯一方法是使用10个线程.如果我执行任何其他操作,性能都会下降.

有人可以告诉我发生了什么事吗?

预先感谢,

-Donald

I''m not clear on how the whole threading process works with regards to the optimal number of threads to create. I''ve heard/read that I should only create a number of threads that corresponds to the number of processors my machine is running. Example: 4 threads for a quad core processor, 2 threads for a dual core processor, etc...

So what happens if I''m running a quad core machine and I create 10 threads to handle some really intensive calculations and database operations?

The reason I ask this is because I''m actually running a quad core machine and doing intensive math calcs and database operations (inserts and updates) in realTime and the only way that my app runs efficiently is with 10 threads. If I run anything less performance degrades.

Can someone please clarify to me what''s going on?

Thanks in advance,

-Donald

推荐答案



Staging computer 1 ---
                        \
Staging computer 2 ---   \
                           calculating computer enques results to ---> storage solution
Staging computer 3 ---   /

Staging computer 4 --- /



当您要进行大量计算时,将IO移开通常是唯一真正的解决方案.与将结果放入消息队列解决方案相比,数据库IO的价格要高得多,特别是如果您使用的是以智能方式处理负载平衡的东西.

问候
Espen Harlinn



Moving IO out of the way is often the only real solution when you''re doing heavy calculations. Database IO is *much* more expensive then enquing results to a message quing solution, especially if you''re using something that handles load balancing in an intelligent way.

Regards
Espen Harlinn


这篇关于根据处理器/内核创建线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:30
查看更多