Nginx should be fast - at least people say so.
I can't get nginx fast. For benchmarking, i use
siege in multiple configurations for simulating high loads. So i tried to load-balance a single server (i know load balancing a single server is rather useless, but for testing the load-balancer itself this is valid). I've set up an already optimized apache reverse proxy as reference. I get around 80tps via nginx and around 350tps using apache when i try getting the same - not cached - file from the same backend server. Of course the hardware/os is the same (current dual-core cpu, 2G ram, Ubuntu Server 16.04).
I tried already changing workers, maximum connections, poll-methods, buffer sizes for proxying, waiting times and buffers for clients. I can see a low load on the system, one nginx uses around 1 percent of the CPU and connections will wait sometime around 5 to 6 seconds. As i want to measure the performance of the reverse proxy i do not want to cache anything in this test.
So the question is: How to optimize the Performance of nginx as non-caching reverse proxy?
siege -c 100 -b -r 100 -v <loadbalancer>/favicon.ico
Update: A bit of config, as requested. For keeping the question serverfault-conform, please answer generally about useful about parameters.
This config is not very clean, i know. But it shows more or less what i already tried. It is derived from the default configuration from the nginx-package in Ubuntu.
The connection takes the following way:
+--- apache2 ---+ | | siege -+ +--> some webserver (not of interest) | | +--- nginx -----+
So the data transmitted via nginx or apache2 does not matter as long there is no cache involved and the same url (in this case a static file) is used for testing. The caching mechanism was not activated intentionally at any of the webservers.
The config in apache uses mpm_worker.
ThreadLimit 600 StartServers 4 ServerLimit 11 MinSpareThreads 50 MaxSpareThreads 100 ThreadsPerChild 200 MaxClients 1000 MaxRequestsPerChild 20000
Example outputs of the above siege command:
$ siege -c 100 -b -r 10 <nginx>/wrapper_2_bg.png ** SIEGE 3.0.5 ** Preparing 100 concurrent users for battle. The server is now under siege.. done. Transactions: 1000 hits Availability: 100.00 % Elapsed time: 11.01 secs Data transferred: 0.12 MB Response time: 0.84 secs Transaction rate: 90.83 trans/sec Throughput: 0.01 MB/sec Concurrency: 76.24 Successful transactions: 1000 Failed transactions: 0 Longest transaction: 6.67 Shortest transaction: 0.03 $ siege -c 100 -b -r 10 <apache>/wrapper_2_bg.png ** SIEGE 3.0.5 ** Preparing 100 concurrent users for battle. The server is now under siege.. done. Transactions: 1000 hits Availability: 100.00 % Elapsed time: 3.16 secs Data transferred: 0.12 MB Response time: 0.22 secs Transaction rate: 316.46 trans/sec Throughput: 0.04 MB/sec Concurrency: 68.95 Successful transactions: 1000 Failed transactions: 0 Longest transaction: 3.06 Shortest transaction: 0.05