Score:0

Specific sequence of round-robin while using nginx as load balancer

cn flag

I have a group of several web applications in docker swarm containers. Some of them have a single instance, some multiple, and that situation may change dynamically, based on our needs (application serve different purposes). I also have a single nginx-based facade which I want to organize a round-robin over all of these instances. It is configured like this:

upstream all {
  server a;
  server b;
  server c;
}

server {
  listen 80;
  location /all/ {
    proxy_pass http://all/
  }
}

For example, services a and c have one instance each, while service b has 2 instances (2 containers). If I start accessing http://host/all/ the sequence in the round robin is this: a, b(1), c, a, b(2), c, .. and so on. I would like to make it instead: a, b(1), b(2), c and so on.. So that I only get back to a after I've got all instances of all other services. And, if we want to upscale a to have 3 instances, the sequence should then become a(1), a(2), a(3), b(1), b(2), c - and back to a(1) and so on.

Is it possible? And how?

PS. In case you are wondering why I would need this: each service has a uniform endpoint that returns health and status information and I'd like to build a dashboard that circles over all the instances of all services and displays a single status page "who is doing what". PPS. My backup plan is to keep calling the API and counting instances until ALL of the counters stop growing. But that means, if there is a significant imbalance (like 1 instance of everything and 50 instances of one), many services would have to answer many redundant times.

Score:0
in flag

You can use server weights for servers, but it should be updated on the nginx side every time the count will change.

And be aware, the round robin by default works per request, in your scenario, if you set weights

upstream all {
    server a;
    server b weight=2;
    server c;
}

and someone else access the server during your query loop, it "stoles" your slot and you skip the desired server

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.