系统信息(ElasticBeanstalk 后面的 AWS EC2 Instance (m4.large)):
地区:us-west-1
内存:8GB
CPU:2 核 / 2.4GHz
PHP 版本:7.0.22 (ZTS) with FPM
Nginx 版本:1.10.2
web/mobile/other 使用了一个 API。每个端点都在发出数据库请求并使用缓存(APCu 或 Redis)
阿帕奇
Apache 每秒处理约 40 个请求。延迟约为 500-1200 毫秒(取决于 API 端点)。
Nginx
然后我们决定迁移到 Nginx。但面对奇怪的行为 - 吞吐量下降到每秒约 20 个请求。并且延迟不断增加(例如:测试以 300ms 开始,以 >31000ms 结束)
/etc/nginx/nginx.conf:
user webapp;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 10000;
error_log /var/log/nginx/error.log;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 4096;
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;
types_hash_max_size 2048;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
charset utf-8;
client_max_body_size 50m;
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/json;
gzip_disable "MSIE [1-6]\.";
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream php {
server 127.0.0.1:9000;
}
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
}
/fpm/pools/www.conf:
[www]
user = webapp
group = webapp
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 75
pm.start_servers = 30
pm.min_spare_servers = 30
pm.max_spare_servers = 35
pm.max_requests = 500
... the rest is default
性能由Apache Jmeter测量,使用自定义场景。测试从同一区域(另一个 EC2 实例)运行。
卷曲统计:
lookup: 0.125
connect: 0.125
appconnect: 0.221
pretransfer: 0.221
redirect: 0.137
starttransfer: 0.252
total: 0.389
tcptraceroute 也很完美(1ms)
请指教!我自己找不到问题的原因.. 谢谢!