Search code examples
c++windowsmultithreadingarchitecturemultiprocess

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.


Solution

  • 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.