Round-robin (RR) is one of the algorithms employed by schedulers in computing. Jobs are assigned to each worker in circular order, It’s simple but useful.
I have a web server writing by node just for front-end display, APIs are most holding by back-end servers. So I have 2 functions supporting my structure. The first is health check helping me check whether the back-end server is ready; and the other one is round robin scheduling, to ensure an even distribution.
Most of the time, I need 1:1 distribution, but sometimes there should be a weighting, so I wrote a weighted round robin module in nodejs just like nginx.
For Example, A B C’s weight is 2 1 1, and the result should be
a
b
a
c
a
b
a
c
a
b
a
c
…
The source code is available on GitHub page.
can u send the step step procedure for coding
Hi, you can follow the example in the github page. Moreover, it is also simple enough that you can just look into the code. 🙂