moleculer
moleculer copied to clipboard
Feat: moleculer-runner in cluster mode with settings instance by service
Describe the solution you'd like Broker in runner cluster mode load all services by default and create every service replicate. Need settings and logic in moleculer-runner for load services on every worker in cluster and every service.
In service add internal params $cluster: false or number replicate. For for compatibility I suggest set default by true or 'max'.
Example: For service1 set $cluster: 1. For service2, nothing (by default max). For service3, set $cluster: 3.
As a result, we should see with moleculer-runner -i 10 service1 - 1 instance service2 - 10 instances service3 - 3 instances
The problem is that, you can't access the service schema before loading it. So maybe you can define them in broker metadata and process that in the Runner cluster mode, e.g:
metadata: {
$cluster: {
service1: 1,
service2: 10,
service3: 3
}
}
I am thinking of a variant with dynamic worker balancing. We can define the logic for connecting services in the loadService method for loading services, add a check for already running instances in the registry and compare with the installed settings.
Thus, rebalancing will occur every respawn trying to load all services. And it will not load those of which the required number is already in the registry.
I understand that this will make the application start slowly. It will take a while for each worker to make sure the exact number of running instances is accurate.
I think this can be implemented as a middleware without modifying the core modules because via broker
it can start/stop services anytime.
In terms of container architecture, this was my wrong suggestion. It is correct when there is one process per 1 CPU inside the container without a race for resources and control over the container.