Skip to content

Instantly share code, notes, and snippets.

@Code-Hex
Last active September 9, 2023 15:08
Show Gist options
  • Save Code-Hex/c387be3a59b1feae03561acdfb383d06 to your computer and use it in GitHub Desktop.
Save Code-Hex/c387be3a59b1feae03561acdfb383d06 to your computer and use it in GitHub Desktop.
Research performance nginx per configuration

wrk -c 100 -t 4 -d 10 http://127.0.0.1:8080/

Default configuration

nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

default.conf

server {
    listen       80;
    server_name  localhost;
    
    root   /usr/share/nginx/html;
    index  index.html index.htm;

    location / {
        try_files $uri $uri/ 404;
    }
}

--- Result
Requests/sec: 2997.74

Added more worker_connections

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 16:44:13.000000000 +0900
@@ -7,7 +7,7 @@
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
 }

--- Result
Requests/sec: 3225.39

Added more worker_processes

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 16:41:42.000000000 +0900
@@ -1,13 +1,13 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
 }

--- Result
Requests/sec: 3572.28

Added accept_mutex_delay

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 16:38:39.000000000 +0900
@@ -1,13 +1,14 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
 }
 

--- Result
Requests/sec: 3911.89

Added tcp_nopush: on

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 17:17:59.000000000 +0900
@@ -1,13 +1,14 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
 }
 
 
@@ -22,7 +23,7 @@
     access_log  /var/log/nginx/access.log  main;
 
     sendfile        on;
-    #tcp_nopush     on;
+    tcp_nopush     on;
 
     keepalive_timeout  65;

--- Result
Requests/sec: 4253.24

Added open_file_cache

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 17:28:00.000000000 +0900
@@ -1,13 +1,14 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
 }
 
 
@@ -22,8 +23,8 @@
     access_log  /var/log/nginx/access.log  main;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
 
     #gzip  on;

--- Result
Requests/sec: 4425.10

Disable access_log

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 17:34:23.000000000 +0900
@@ -1,13 +1,14 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
 }
 
 
@@ -19,11 +20,11 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
 
     #gzip  on;

--- Result
Requests/sec: 6107.40

Added aio threads

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 17:34:23.000000000 +0900
@@ -1,13 +1,14 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
 }
 
 
@@ -19,11 +20,11 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
 
     #gzip  on;
--- data/conf.d/default.conf.before	2017-07-11 15:57:15.000000000 +0900
+++ data/conf.d/default.conf	2017-07-11 17:44:14.000000000 +0900
@@ -6,6 +6,7 @@
     index  index.html index.htm;
 
     location / {
+        aio threads;
         try_files $uri $uri/ 404;
     }
 }

--- Result
Requests/sec: 5222.69

Added tcp_nodelay

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 17:58:36.000000000 +0900
@@ -1,13 +1,14 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
 }
 
 
@@ -19,11 +20,12 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    tcp_nodelay on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
 
     #gzip  on;

--- Result
Requests/sec: 5756.04

Added multi_accept

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 18:03:23.000000000 +0900
@@ -1,13 +1,15 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
+    multi_accept on;
 }
 
 
@@ -19,11 +21,11 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
 
     #gzip  on;

--- Result
Requests/sec: 6104.30

Added reset_timedout_connection

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 18:17:18.000000000 +0900
@@ -1,13 +1,15 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
+    multi_accept on;
 }
 
 
@@ -19,14 +21,15 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
 
     #gzip  on;
+    reset_timedout_connection on;
 
     include /etc/nginx/conf.d/*.conf;
 }

--- Result
Requests/sec: 6078.55

Added use epoll

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 18:42:55.000000000 +0900
@@ -1,13 +1,16 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
+    multi_accept on;
+    use epoll;
 }
 
 
@@ -19,14 +22,15 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
 
     #gzip  on;
 
+
     include /etc/nginx/conf.d/*.conf;
 }

--- Result
Requests/sec: 6139.96

Disable error_log

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 18:47:04.000000000 +0900
@@ -1,13 +1,16 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
+    multi_accept on;
+    use epoll;
 }
 
 
@@ -19,14 +22,16 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
+    error_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
 
     #gzip  on;
 
+
     include /etc/nginx/conf.d/*.conf;
 }

--- Result
Requests/sec: 6245.80

Added keepalive_requests

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 19:01:59.000000000 +0900
@@ -1,13 +1,16 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
+    multi_accept on;
+    use epoll;
 }
 
 
@@ -19,14 +22,17 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
+    error_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
+    keepalive_requests 100000;    
 
     #gzip  on;
 
+
     include /etc/nginx/conf.d/*.conf;
 }

--- Result
Requests/sec: 7192.16

Added worker_rlimit_nofile

--- data/nginx.conf.before	2017-07-11 15:56:47.000000000 +0900
+++ data/nginx.conf	2017-07-11 19:12:04.000000000 +0900
@@ -1,13 +1,17 @@
 
 user  nginx;
-worker_processes  1;
+worker_processes  4;
 
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;
 
+worker_rlimit_nofile 100000;
 
 events {
-    worker_connections  1024;
+    worker_connections  10240;
+    accept_mutex_delay 100ms;
+    multi_accept on;
+    use epoll;
 }
 
 
@@ -19,14 +23,14 @@
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
 
-    access_log  /var/log/nginx/access.log  main;
+    access_log off;
+    error_log off;
 
     sendfile        on;
-    #tcp_nopush     on;
-
+    tcp_nopush     on;
+    open_file_cache max=100 inactive=20s;
     keepalive_timeout  65;
-
-    #gzip  on;
+    keepalive_requests 100000;    
 
     include /etc/nginx/conf.d/*.conf;
 }

--- Result
Requests/sec: 7240.11

@Code-Hex
Copy link
Author

Code-Hex commented Jul 11, 2017

Environment:

  • Mac OS X 10.11
  • Processor: 2 GHz Intel Core i7
  • Memory: 8 GB 1600 MHz DDR3
  • Docker with official Nginx image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment