对于多线程和多进程的性能差异 [英] Performance difference for multi-thread and multi-process

查看:340
本文介绍了对于多线程和多进程的性能差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年前,在Windows环境下,我做了一些测试,通过让CPU的计算密集型+内存访问密集型+ I / O访问密集型应用程序运行多个实例。我开发了两个版本:一个是多任务处理下运行,另一种是在多线程运行

我发现性能多的多处理好。我读别的地方(但我不记得站点)。

其中规定,原因是在多线程,它们是激战的单条内存流水线和I / O管道,相对于多处理器使得性能更差

不过,我找不到那篇文章了。我想知道,直到今天,下面是否仍然适用?


  

在Windows中,具有算法
  多处理下code运行,有一个高
  机会表现会
  比多线程更好。



解决方案

这取决于有多少不同的线程或进程(我将使用通用术语任务对他们俩的),需要沟通,特别是共享内存:这很简单,廉价,​​快速的线程,但不是所有的过程,因此,如果有很多这是怎么回事,我敢打赌,流程的绩效是的的将击败线程。

此外,过程(特别是在Windows上)的重上手,所以如果有很多的任务启动出现,再一次线程可以很容易地在性能方面击败流程。

接下来,你可以有超线程的CPU,它可以运行(至少)上的一个核心两个线程非常迅速 - 但是,没有过程(因为超线程线程不能使用不同的地址空间来) - 另一起案件中,线程可以赢得的性能,明智的。

如果没有这些因素的适用,那么比赛应该没有比一条领带更好,反正。

A few years ago, in the Windows environment, I did some testing, by letting multiple instances of CPU computation intensive + memory access intensive + I/O access intensive application run. I developed 2 versions: One is running under multi-processing, another is running under multi-threading.

I found that the performance is much better for multi-processing. I read somewhere else (but I can't remember the site).

Which states that the reason is that under multi-threading, they are "fighting" for a single memory pipeline and I/O pipeline, which makes the performance worse compared to multi-processing

However, I can't find that article anymore. I was wondering, till today, whether the below still hold true?

In Windows, having the algorithm code run under multi-processing, there is a high chance that the performance will be better than multi-threading.

解决方案

It depends on how much the various threads or processes (I'll be using the collective term "tasks" for both of them) need to communicate, especially by sharing memory: that's easy, cheap and fast for threads, but not at all for processes, so, if a lot of it is going on, I bet processes' performance is not going to beat threads'.

Also, processes (esp. on Windows) are "heavier" to get started, so if a lot of "task starts" occur, again threads can easily beat processes in terms of performance.

Next, you can have CPUs with "hyperthreading", which can run (at least) two threads on a core very rapidly -- but, not processes (since the "hyperthreaded" threads cannot be using distinct address spaces) -- yet another case in which threads can win performance-wise.

If none of these considerations apply, then the race should be no better than a tie, anyway.

这篇关于对于多线程和多进程的性能差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆