Choice between multithreading and multi-processing: When to use what
Deepak Kumar
Propelling AI To Reinvent The Future ||Author|| 150+ Mentorship|| Leader || Innovator || Machine learning Specialist || Distributed architecture | IoT | Cloud Computing
Introduction
Single threaded and single process solution is normal practice. For example, if you open the text editor, it will start a single threaded process. For each file, it will start a new text editor instance. This works well.
In a typical scenario, for high performance and scalable solution, designer needs to use multiple threads which runs on multi-core cpu in parallel. For example, consider online shopping website. The load on http web process depends on number of people accessing the site. To provide better throughput and response time, designer of such site must consider parallelism of operation.
Comparison between Thread and Process
?When to select multithreading or multi process
Choice between multithreading and multi-process depends on the problem at hand. In case parallelism is needed and the parallel running entity are related in terms of data, then multithreading can be the first choice of evaluation. We can even consider hybrid model. Below there are few interesting use-cases.
Use-case1
If we design a http web process, a designated master thread can handle http connection. Multiple worker thread can serve the http request. Note that in this case,?
Use-case2
In this use-case, programmer needs to collect info from various sources and then store these info to database.?
Here there are two components:?
For collector, multiple processes makes more sense. I am telling this since?
For database management, single process with multiple threads makes more sense since