多处理器与多核之间的区别
我的应用程序在 4 个并发线程上运行。我可以将这些线程设置为多线程和单线程(MTA / STA)。当我声明它们为 STA 时,结果比我声明它们为 MTA 时要快。它是用vb.net编写的,我使用2003服务器(Windows)标准版作为操作系统,处理器是单核和四核。
我应该做什么才能让它更快?
我可以将处理器数量增加到 2 个,或者可以使用六核/八核处理器代替。 有人可以建议吗?
谢谢。
My application runs on 4 simultaneous threads. I can make those threads as multi threads as well as single thread (MTA / STA). When I declare them STA the result is faster than when I declare them MTA. Its written in vb.net and i am using 2003 server (windows) standard edition as operating system, The processor is single and quad core.
What should I do to make it faster?
I can increase number of processor to 2, or I can use hexcore/ octal core processor instead.
Can anyone suggest?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
多处理器意味着主板上有多个处理器芯片。多核意味着一个芯片上有多个处理单元。多个处理器将具有不同的前端总线,并且多个内核通常会共享 L2 缓存。这两者各有优势,具体取决于您在做什么。
对于你问题的第二部分,答案不太具体。如果您正在做的工作不是那么复杂,那么多个线程的开销可能会超过性能提升。另外,如果您的线程尝试访问相同的共享内存,锁定会减慢它们的速度。您的线程在对磁盘进行 IO 操作时也可能遇到瓶颈。如果不了解您实际在做什么,就很难说您的问题是什么以及如何进一步进行。购买更新、更快、更大的处理器会加快速度,但它并不能解决为什么你认为你的程序运行速度不快的问题。在开始花钱解决问题之前,先花一些时间处理代码。
Multiple processors means that the motherboard has multiple processors chips on it. Multicore means that a chip has multiple processing units on it. Multiple processors will have different front side busses and multiple cores will generally share L2 cache. Both of these have advantages depending on what you are doing.
For the second part of your question, the answer is less concrete. If the work you are doing is not that complicated, the overhead of multiple threads could outweigh the performance gains. Also, if your threads are trying to access the same shared memory, locking will slow them down. Your threads could also be bottle-necked doing IO to the disk. Without information about what you are actually doing, it is hard to say what is your problem and how to proceed further. Buying a newer, faster, bigger processor will speed things up, but it doesn't address the issue of why you think your program is not running faster. Spend some time working with the code before you start throwing money at the problem.
MTA 应该比 STA 慢,因为正如其名称所示,该单元中可能运行多个线程,因此很多事情都必须涉及锁定。即使只有一个线程在那里运行,仍然必须完成锁定,从而产生开销。因此,在 4x STA 上运行的 4 个线程将比在 4x MTA 上运行的 4 个线程更快,即使线程和单元是一对一匹配的。如果您不打算在对象上运行多个线程,那么通过使公寓模式 MTA 不会获得任何好处。
添加更多处理器和/或内核将对您有所帮助,因为您的四个线程可能在不同的内核上运行。
但是,添加的内核数多于线程数不会提高性能,因为一个线程仅在一个内核上运行。在您的示例中,您的四个线程应在 4 个内核上运行(无论它们是否属于同一处理器)。为系统程序(假设您不运行其他任何东西)和驱动程序添加一两个核心,您可能会达到极限。添加更多核心不会有任何帮助,因为除非增加线程数,否则这些核心可能处于空闲状态。
其他因素也会影响您的并发性能:如果您的共享资源是线程之间的争用点,并且您的线程一直在等待该资源上的锁,那么添加更多内核可能不会对您有帮助,因为您的瓶颈是在访问共享资源时,线程只是运行空闲等待。在这种情况下,升级到更快的 CPU(就时钟速度而言)将会更快,因为它提高了您满意的资源的释放速度。
添加处理器通常比在同一处理器上添加内核更快,因为不同的内核共享单个处理器内的内部资源,并且如果一个内核正在使用某种资源,则其他内核会阻塞。然而,我听说过这样的情况:当多个处理器必须访问相同的内存位置时,添加核心的速度会更快,并且相同的信息可以存储在一个处理器内的缓存中,并在所有核心之间共享。
MTA should be slower than STA because, as its name shows, multiple number of threads may be running in that apartment, so a lot of things have to involve locking. Even if you only have one single thread running there, the locking must still be done, thus incurring overhead. Therefore, 4 threads running on 4x STA will be faster than 4 threads running on 4x MTA, even if the threads and apartments are matched one-to-one. You are not gaining anything by making your apartment mode MTA if you don't intend to run more than one thread on the object.
Add more processors and/or cores will help you as your four threads are likely to be running on different cores.
However, adding more cores than the number of threads will not add performance, since one thread runs only on one core. In your example, your four threads should run on 4 cores (whether they belong to the same processor). Add one or two cores for system programs (assuming you don't run anything else) and drivers, and you probably max out. Adding more cores will not help as those cores may be idle unless you increase you thread count.
Other things affect your concurrency performance as well: if you have a shared resource that is a contention point among your threads, and your threads are waiting for locks on this resource all the time, then adding more cores may not help you because your bottleneck is in accessing the shared resource and threads are just running idle waiting. In this case, upgrading to a faster CPU (in terms of clock speed) will be faster as it increases the speed that your contented resources are being released.
Adding processors typically will be faster than adding cores on the same processor, as different cores share internal resources within a single processor, and if one core is using a resource, other cores block. However, I've heard about situations that adding cores are faster when multiple processors have to access the same memory locations and that same information can be stored in a cache inside one processor, shared among all its cores.