Question

Nginx TCP load balancer performs worse than single web server

I have a simple nginx tcp load balancer that simply passes connections to the web servers. The requests per second is lower using the load balancer with 2 servers than one of those servers by itself. The load balancer also doesn’t increase its requests per second when adding additional web servers… This doesn’t seem right. Any ideas what could be causing this?

# loads stream module
load_module /usr/lib/nginx/modules/ngx_stream_module.so;

# sets user to default user for web server
user www-data;

# sets number of cpu cores to use
worker_processes auto;

# customizes how to handle connections
events {

    # sets number of connections to use per cpu core
    worker_connections 1024;
    
    # uses efficient connection processing method
    use epoll;
    
    # sets worker processes to accept all connections
    multi_accept on;

}

# customizes how to handle incoming tcp connections
stream {

    # distributes secure connections between specified web servers
    upstream web_servers_insecure {
        
        # sets ip address and port of web servers
        server 147.182.205.7:80;
        #server 128.199.3.255:80;
        
    }

    # customizes how to handle insecure connections
    server {
        
        # sets port
        listen 80;
        
        # sends tcp connections to upstream directive
        proxy_pass web_servers_insecure;

    }

    # distributes secure connections between specified web servers
    upstream web_servers_secure {

        # sets ip address and port of web servers
        server 147.182.205.7:443;
        #server 128.199.3.255:443;

    }

    # customizes how to handle secure connections
    server {
        
        # sets port
        listen 443;
        
        # sends connections to upstream directive
        proxy_pass web_servers_secure;

    }

}

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @davidlittlefieldCoral,

I might be wrong but this is to be expected. When you get the request on your Droplet, the Load Balancer one, it needs to take the request and forward it to the proper Droplet. This action takes some time, even if it should be one millisecond or whatever. Again I might be wrong but this is my take on it.

I’m interested to see other answers if there is a real solution to it.