How is the new connection being distributed across the instances when PM2 uses the round-robin for cluster?

164 Views Asked by At

Recently, I have been exploring the concept, How the PM2 works in cluster mode. assume that, that we have four instances that are running in the cluster mode. and consider instance ids are 13, 14, 15, 16

enter image description here

By default PM2 uses the node cluster module for clustering, the node cluster mode default approach is round-robin. PM2 also uses the default approach.

When I hit the API, the request goes to instance 13, then I hit that API again it goes to instance 13 if that instance 13 is free (none of the requests come to that instance), if not the request goes to 14. considered as after a few minutes all instance are free(no more request comes to none of the instances). Now if I hit the API, that request goes to the next instance 14, instead of going to the instance 13.

Here my question is, When I hit the API continuously, all request goes to one instance if that instance is free. if I hit the API after some time, the request goes to the next instance even if all instances are free. Does PM2 manage any time duration for each instance to handle the incoming requests? If you know the answer kindly let me know.

0

There are 0 best solutions below