It's the basis of PM2, which is a familiar orchestrator for this kind of multi-instance applications. Is anybody using PM2 here? Please raise your hand. Okay. So you know how it works. The problem is that this IPC, so Inter-Process Communication, via Unix web socket, is adding for each of your requests a 30% overhead in the response time. You're wasting 30% out of your application logic, business logic, and so forth. So that's the idea. I just talk about this, but that's the graphical representation.
So basically, the node master will basically talk to the operating system to deal with the network layer, accept connection, route them to one of the possible worker, and then eventually send the response back. But there is the overhead. Then there is another problem, which is pretty peculiar to Node.js. When the system is overloaded, ideally, rather than accepting new connection and making the situation even worse, you maybe want to return to the customer a 503 response. The problem is that the server can reject this very early and say, you know what? I'm busy. Come back later. I know it's not nice, but it's better than letting you wait for 20 seconds.
So they immediately reject with 503. The problem is that this is not possible in Node, because the idea is that in order to reject a request, you have to reject it when you actually process it. And in order to process it, you have to accept it in the event loop. By the time you are getting to processing that request, the customer has already waited for a long time. And also, which is also make it even worse, this request is still in the event loop. So all the associated requests, network sockets, eventually already loaded data, and so forth, are still in your RAM for no reason at all. I mean, you're filling up your RAM for requests that you're not even processing. I mean, we are getting in the very horrible scenarios, right? And since we've just been talking about Next.js in the previous talk with Wyatt, Next.js, but even other frameworks, I'm just talking about Next because it's our case study today, but this is generally true for all other frameworks like that, TimeStack, Nuxt, whatever you want to think about.
Comments