Home > Software engineering >  Can I have multiple event loop in nodejs microservices?
Can I have multiple event loop in nodejs microservices?

Time:08-04

I Have 4 Microservices, named "auth_ms","coin_ms","device_ms" and setting_ms. I'm running all 4 Microservices on different ports, for example: 3000, 3001, 3002 and 3003.

My Question: By running these 4 servers on different port, do we have 4 event-loops ? if NOT, then if I put it in Docker containers does it have 4 event-loops? Suppose there is only 1 event loop for everything then how does microservices help in processing?

CodePudding user response:

Each of your microservices are running as different processes locally, so they will have separate event-loops. This also applies to Docker containers, where the services will be completely isolated.

CodePudding user response:

When you write node index.js in the terminal you are creating a NodeJS process, which contains all of the goodies of node, including the event loop.

Assuming your microservices run in separate node instances, then you will have an event loop for every one of your instances of node. And it does not matter if it's in docker or not as long as there are separate processes running.

Now, if there is only one OS process, then only one action can be performed at a time. And worse yet, if you run it on multi-core machine, only one of the cores will be used, wasting all of the potential resources that can be utilized for processing. For this reason in production environment I usually run container for every vCPU there is available.

So what you want to have is - separate processes for every service you have (separate docker containers also count) and the rest will be handled by the system.

  • Related