Weighted Round Robin In Nodejs

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.

2 thoughts on “Weighted Round Robin In Nodejs

    1. henry Post author

      Hi, you can follow the example in the github page. Moreover, it is also simple enough that you can just look into the code. 🙂

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.