Thread based vs. Event based

There are 2 main approaches how to handle requests from Clients to a web server:

Thread based

On a thread based system the web server creates one thread per request and all the work for this request is handled by that thread.

This also means, that the maximum of available threads on a computer determines how many concurrent users can connect to the web server.

Event based

On an event based system every request will be put in a “queue” which then is processed by 1 web server thread.

With that you avoid the “overhead” of creating a new thread for each request.

But this also means, that e.g. a very complex and long request blocks all request since it needs to be done before all the other requests can be processed.

But due to the fact, that JavaScript can be written asynchronously no “blocking” can occur and therefore no (direct) performance problem can be felt by the end-user.

Node.js “Event Loop” visualized

Node.js Event Loop

Source: https://stackoverflow.com/questions/21596172/what-function-gets-put-into-eventloop-in-nodejs-and-js

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.