title: Nginx round robin load balancing is not as expected
body: <p>We are connecting to a system where in 4 ports are exposed to serve the grpc requests. Used nginx as load balancer to forward the 4 client grpc requests with below configuration:</p>
  
  <pre><code>user www-data;
  worker_processes auto;
  pid /run/nginx.pid;
  include /etc/nginx/modules-enabled/*.conf;
  
  events {
          worker_connections 768;
          # multi_accept on;
  }
  
  http {
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent"';
  
      map $http_upgrade $connection_upgrade {
          default upgrade;
          ''      close;
      }
      upstream backend{
          #least_conn;
          server localhost:9000 weight=1 max_conns=1;
          server localhost:9001 weight=1 max_conns=1;
          server localhost:9002 weight=1 max_conns=1;
          server localhost:9003 weight=1 max_conns=1;
          }
  
      server {
          listen 80 http2;
  
          access_log /tmp/access.log main;
          error_log /tmp/error.log error;
  
          proxy_buffering off;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Scheme $scheme;
          proxy_set_header Host $http_host;
  
          location / {
                  #eepalive_timeout 0;
                  grpc_pass grpc://backend;
                  grpc_pass_header userid;
                  grpc_pass_header transid;
          }
      }
  }
  </code></pre>
  
  <p>It is observed that few times all client 4 requests goes to all the 4 ports but sometimes (say 30%) to only 2 ports/3ports. Seems like default round robin is not happening with the NGINX as expected. We tried all possibilities like max_conns, least_conn, weight but no luck. </p>
  
  <p>Seems like I have encountered the issue as in below links:</p>
  
  <pre><code>https://serverfault.com/questions/895116/nginx-round-robin-nor-exactly-round-robin
  https://stackoverflow.com/questions/40859396/how-to-test-load-balancing-in-nginx
  </code></pre>
  
  <p>When i was going through Quora found that "fair" module in nginx would resolve this. </p>
  
  <pre><code>    "The Nginx fair proxy balancer enhances the standard round-robin load 
      balancer provided with Nginx so that it will track busy back end servers (e.g. Thin, Ebb, Mongrel) and balance the load to non-busy server processes. "
  
  https://www.quora.com/What-is-the-best-way-to-get-Nginx-to-do-smart-load-balancing
  </code></pre>
  
  <p>I tried using "fair" module with NGINX from source but encountered so many issues. I could not start the NGINX itself. Can anyone help with this issue?</p>