I have been searching if there is a way to handle large scale HTTP requests with Express.js. I know Node.js has 'workers' starting at version 13 to do the multithreading, but in terms of handling multiple HTTP requests to a single endpoint, how would I go about doing that and scaling up?
For example, if 10,000 requests come at the same time, another thread would open up and deal with the other request to speed up the process. Does it do it automatically or do I need to configure something on it?
Thanks!
CodePudding user response:
Express.js is designed with the event loop philosophy, expecting each request-response cycle to take negligible total CPU time (ignoring any waiting times due to I/O). This allows an Express.js server to efficiently respond to many requests on a single thread. To make this work, it is expected that any request that demands more than negligible CPU time will create a Worker thread, or spawn a process, to do the computation away from the event loop thread. This responsibility falls to the programmer.
If your Express.js app is still not able to keep up with the volume of the requests even though this philosophy is being followed, the solution is to scale up above its level using a load balancer, whether on a web server level (e.g. Apache httpd's mod_load_balancer), or on DNS level.