coo*_*ndy 6 webserver reverse-proxy nginx node.js
我正在运行一个简单的ab测试来获取针对我的节点应用程序的性能指标。
当我ab直接针对应用程序运行时(针对10.0.0.5端口运行 5 个测试31005),我看到吞吐量为~1100 req/sec:
> ab -q -n 12000 -c 300 -k "http://10.0.0.5:31005" | grep "Requests per second"
Requests per second: 1156.51 [#/sec] (mean)
Requests per second: 1201.85 [#/sec] (mean)
Requests per second: 1238.40 [#/sec] (mean)
Requests per second: 1392.68 [#/sec] (mean)
Requests per second: 1294.58 [#/sec] (mean)
Run Code Online (Sandbox Code Playgroud)
10.0.0.4同样,当我将 HAPrxoy (在port上运行8888)放在我的节点应用程序前面并运行相同的测试时,我看到非常相似的吞吐量:
> ab -q -n 12000 -c 300 -k "http://10.0.0.4:8888" | grep "Requests per second"
Requests per second: 1179.97 [#/sec] (mean)
Requests per second: 1176.60 [#/sec] (mean)
Requests per second: 1308.40 [#/sec] (mean)
Requests per second: 1294.56 [#/sec] (mean)
Requests per second: 1246.76 [#/sec] (mean)
Run Code Online (Sandbox Code Playgroud)
然而,当我通过 Nginx 运行它时(也在 上运行10.0.0.4,但在端口上运行80),我发现性能差了大约 30%:
> ab -q -n 12000 -c 300 -k "http://10.0.0.4" | grep "Requests per second"
Requests per second: 836.16 [#/sec] (mean)
Requests per second: 803.62 [#/sec] (mean)
Requests per second: 766.50 [#/sec] (mean)
Requests per second: 847.16 [#/sec] (mean)
Requests per second: 852.60 [#/sec] (mean)
Run Code Online (Sandbox Code Playgroud)
我的 nginx 配置非常简单
worker_processes 2;
worker_rlimit_nofile 40000;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 40000;
use epoll;
multi_accept on;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100000;
client_body_buffer_size 128k;
client_max_body_size 10m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
output_buffers 1 32k;
postpone_output 1460;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_vary off;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml;
gzip_min_length 1000;
gzip_disable "MSIE [1-6]\.";
server {
listen 80;
server_name 10.0.0.4;
access_log /var/log/nginx/app-access.log main;
error_log /var/log/nginx/app-error.log;
location / {
proxy_pass http://10.0.0.5:31005$request_uri;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用 检查了资源使用情况top,但我从未看到服务器上的 CPU 或内存达到最大值。我正在具有 4 GB 内存的双核上运行,我认为这足以处理我施加的负载。
此外,ulimit -n还返回40000.
您能看出我的 Nginx 性能如此差的原因吗?
附加信息:
Nginx版本
nginx version: nginx/1.10.0 (Ubuntu)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
810 次 |
| 最近记录: |