Moleculer: control number of instances on each broker

Created on 10 Apr 2018  路  6Comments  路  Source: moleculerjs/moleculer

Hi guys is there a way to control the number of instances on each broker?

Question

Most helpful comment

HI @cesar2064 how are you?

You can have multiple services working in one node js instance, it's just business logic.

If you want to have multiple node js instances you have many options:

  1. clustering using moleculer-runner with the flag --instances (http://moleculer.services/0.12/docs/runner.html)
  2. using --scale flag if you are using docker
  3. kubernetes
  4. or just executing multiple times your node js process

Remember that for all of this cases you have to define a transport in order to allow to work the service discovery of moleculer and really important to have each node js instance their own unique id.

This is something really cool to understand the different possible architectures for your nodes and services: http://moleculer.services/0.12/docs/nodes.html

All 6 comments

What do you mean?

Well each broker is a service or microservice which run as fork or cluster right?, or each broker runs in the same instance?. May be I need to understand this part first.

The Broker is running your services. It can run one or more services. And you can execute multiple brokers too. So it's your choice that how many broker instances are running.

Yes, I understand it, but does each service run in a separate node js instance?. What happens if I want to use a service which is heavy and I want it to use more cores?, like PM2 does or node js cluster mode. Or the lib simply run each service in same thread?

HI @cesar2064 how are you?

You can have multiple services working in one node js instance, it's just business logic.

If you want to have multiple node js instances you have many options:

  1. clustering using moleculer-runner with the flag --instances (http://moleculer.services/0.12/docs/runner.html)
  2. using --scale flag if you are using docker
  3. kubernetes
  4. or just executing multiple times your node js process

Remember that for all of this cases you have to define a transport in order to allow to work the service discovery of moleculer and really important to have each node js instance their own unique id.

This is something really cool to understand the different possible architectures for your nodes and services: http://moleculer.services/0.12/docs/nodes.html

this is so cool, thanks @tinchoz49 and @icebob

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kamil93 picture Kamil93  路  3Comments

slinkardbrandon picture slinkardbrandon  路  4Comments

icebob picture icebob  路  3Comments

kesslerdev picture kesslerdev  路  4Comments

jodaks picture jodaks  路  5Comments