node.js – Difference between Multi and Single Thread


In terms of processes, what is the difference between multi-thread and single-thread? How will the two forms work with a requisition?


It has more architectures besides single-thread (ST) and multi-thread (MT). Basically, the ST can only handle one request at a time, so the processing of each one cannot be time-consuming, nor can it block (for example, waiting for the database). The MT, assuming that one thread is created per request, can handle several requests in parallel, even if they take a long time or block them.

An ST server can be effective as long as it never crashes. Node.js is asynchronous so it doesn't crash. Any time-consuming processing must be delegated to another process, which can also be done in Node with subprocess.

Another way to approach the problem: Apache's prefork creates a pool of subprocesses, and delegates requests to each subprocess as they arrive. This ensures parallelism and avoids the complexities of MT programming. This can also be implemented in Node but Apache delivers this from the factory, which makes life easier for the PHP developer for example, as he doesn't have to worry if he's blocking.

Scroll to Top