Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance difference for multi-thread and multi-process

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.

like image 326
Cheok Yan Cheng Avatar asked Jul 31 '10 02:07

Cheok Yan Cheng


2 Answers

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.

like image 177
Alex Martelli Avatar answered Oct 06 '22 10:10

Alex Martelli


I'm not sure what the quote even means. It's very close to nonsense.

The primary thing that in-proc threads share is virtual memory address space.

like image 34
Richard Berg Avatar answered Oct 06 '22 10:10

Richard Berg