【发布时间】:2021-01-23 20:51:44
【问题描述】:
我们正在我们应用程序的网页上使用 locust(1000 个用户) 执行负载测试。
实例类型:t3a.medium 该实例在负载均衡器后面运行。我们正在使用 RDS Aurora 数据库,该数据库的 CPU 利用率达到 70% 左右。 EC2 实例指标正常。编辑:实例内存消耗在可用 4 GB 中的 800 MB 以内
有多个502 Server error: Bad Gateway,有时还有500 和520 错误。
错误 1:
2020/10/08 16:58:21 [error] 4344#4344: *41841 connect() to unix:/var/run/php/php7.2-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: <PublicIP>, server: <Domain name>, request: "GET <webpage> HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "<Domain name>"
错误 2(警报):
2020/10/08 19:15:11 [alert] 9109#9109: *105735 socket() failed (24: Too many open files) while connecting to upstream, client: <PublicIP>, server: <Domain name>, request: "GET <webpage> HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "<Domain name>"
列出配置文件:
Nginx 配置
server {
listen 80;
listen [::]:80;
root /var/www/####;
index index.php;
access_log /var/log/nginx/###access.log;
error_log /var/log/nginx/####error.log ;
server_name #####;
client_max_body_size 100M;
autoindex off;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
/etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 8096;
multi_accept on;
use epoll;
epoll_events 512;
}
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;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_types text/xml text/css;
gzip_http_version 1.1;
gzip_vary on;
gzip_disable "MSIE [4-6] \.";
include /etc/nginx/conf.d/*.conf;
}
/etc/php/7.2/fpm/php-fpm.conf
emergency_restart_threshold 10
emergency_restart_interval 1m
process_control_timeout 10s
php-fpm 重要参数:
user = www-data
group = www-data
listen = /run/php/php7.2-fpm.sock
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
pm = static
pm.max_children = 300
/etc/security/limits.conf
nginx soft nofile 30000
nginx hard nofile 50000
/etc/sysctl.conf
net.nf_conntrack_max = 131072
net.core.somaxconn = 131072
net.core.netdev_max_backlog = 65535
kernel.msgmnb = 131072
kernel.msgmax = 131072
fs.file-max = 131072
我们缺少什么?谁能指出正确的方向?
【问题讨论】:
-
这看起来你的服务器可能内存不足,因为它们产生了 php-fpm 子节点。这将导致间歇性的 502/504,并且不会使实例在 AWS 控制面板中显得不健康。假设您在测试环境中,您可以编写一个脚本来检查服务器上的可用内存,并让它在它低于某个值时重新启动 fpm 服务。我不会在 prod 中这样做,但它至少会缩小问题的范围。
-
另一个潜在问题是您可能正在耗尽极光中可用的连接数。您允许 8000 名工作人员,但 RDS 根据实例大小强制执行 max_connections - 检查 this document 并确认您没有违反该规定
-
@TheGentleman 在可用的 4 GB 内存中,它永远不会超过 800 MB 的使用量。我们已经确认在测试运行期间。
-
@mcfinnigan,谢谢调查
标签: php amazon-web-services nginx amazon-ec2