What is NGINX ?

NGINX is a load balancer which enhance performance and fault tolerance with application servers. I m experienced with Apache tomcat with load balancing with NGINX.

Why NGINX ?

In approach of Apache Tomcat application server , it can manager performance and accuracy with low and medium load. But when it comes with high load there will be performance and fault issues. To manage this scenario we are using load balancers like NGINX.  NGINX uses technique of Asynchronous operations to perform high concurrency operations avoiding thread blocking or overhead. This scenario tomcat can have multiple benefits such as

    • Achieve event driven architecture.
    • HTTP/2 support
    • Load balancing
  • SSL/TLS termination when offload work load from tomcat application server.
  • Caching

How it works

This NGINX article has explained in details how it works and NGINX architecture.

https://www.nginx.com/blog/inside-nginx-how-we-designed-for-pe

Below article shows how you can load balance using NGINX (open source version ) and NGINX+ (Commercial version) .

Load balancing mechanisms supported by NGINX.

01. Round robin load balancing

This mechanism will distribute the load in between servers in round robin technique. And this is the default load balancing mechanism in NGINX. Below I have added an example for load balancing using round robin.

http {
upstream myapp1 {
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
}
server {
listen 80;

location / {
proxy_pass http://myapp1;
}
}
}

There are three instances for same application such as srv1,2,3. Round robin will be applied when we did not configured any balancing method. Proxy pass will be applied for the DNS of  “myapp1”. Moreover this example is applied for http and if you need other you have to replace the relevant protocol.

02.  Least connected load balancing

This method will be used when any known requests take longer time to complete than usual. Example we can take bulk upload , bull search and so on.

This scenario NGINX is intelligent to not to distribute much more load to the server which has the function execute longer time. NGINX will distribute load to other least load server than the server which has longer time task.  We can use least_conn syntax to enable least connected load balancing.

upstream myapp1 {
        least_conn;
        server srv1.test.com;
        server srv2.test.com;
        server srv3.test.com;
    }

03. IP hash loading balancing

Both round robin and least connected methods are not guranteed that same client will be redirected to same serve at every time. In case if deployment engineer need that we can use IP hash method.

upstream myapp1 { ip_hash; server srv1.example.com; server srv2.example.com; server srv3.example.com; }

Weighted load balancing

If we consider round robin example above all the servers are distributed the load in equal or less . But if you need to distribute load in different ratio you have to use weight syntax. Example added below.

upstream myapp1 {
        server srv1.example.com weight=3;
        server srv2.example.com;
        server srv3.example.com;
    }

I hope now you have good understanding about NGINX Load Balancing. For more explanation
and other kind details you can search for NGINX documentation.

Leave a Reply

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

WP Facebook Auto Publish Powered By : XYZScripts.com