我已經為以下問題苦苦掙扎了一段時間,非常感謝您的幫助。
由於 php 線程過多,我的網頁伺服器經常完全崩潰。 php進程數穩定在正常範圍內(例如35個進程)。每個行程的執行緒數量隨著時間的推移而不斷增加。幾個小時後,所有 php 進程中的所有執行緒總數都超過 900,此時正常的伺服器操作開始關閉。
以下是我計算行程和執行緒數量的方法:
ps axo pid,nlwp,cmd | grep "pool www"
15674 11 php-fpm: pool www
15675 13 php-fpm: pool www
15676 8 php-fpm: pool www
15677 7 php-fpm: pool www
15678 12 php-fpm: pool www
……還有 30 行類似的行
我在跑步
- 虛擬伺服器
- 8GB 記憶體
- 4 個 vCore
- ubuntu 16.04
- nginx 1.10.3
- PHP-FPM 7.0.3
我的 .../fpm/pool.d/www.conf 看起來像這樣(按字母順序排列):
user = www-data
request_terminate_timeout = 600s
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 35
pm.max_requests = 500
pm.max_children = 72
pm = dynamic
listen.owner = www-data
listen.group = www-data
listen = /run/php/php7.0-fpm.sock
group = www-data
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
env[PATH] = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
env[HOSTNAME] = $HOSTNAME
我的 nginx 設定如下所示:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
client_max_body_size 501m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 3;
types_hash_max_size 2048;
server_names_hash_max_size 8192;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $host $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
map $status $loggable {
~^404 0;
default 1;
}
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log ;
gzip on;
gzip_disable "msie6";
application/xml+rss text/javascript;
gzip_min_length 1100;
gzip_vary on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_conn addr 50;
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=YOURAPP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
upstream php {
server unix:/run/php/php7.0-fpm.sock;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
server {
listen 443 ssl;
server_name www.mydomain.com;
root /var/www/path/to/webfiles;
# ssl specs here
# some general location stuff here
location ~ \.php$ {
regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $fastcgi_script_name =404;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_cache_bypass 1;
fastcgi_no_cache 1;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_cache YOURAPP;
fastcgi_cache_valid 200 60m;
fastcgi_read_timeout 600s;
}
}
似乎有到伺服器上運行的 z-push 服務的連線。它用於將伺服器資料(聯絡人、日曆、郵件)與行動裝置同步。關閉該特定服務後,執行緒數量停止增加。到目前為止,我無法找到 z-push/nginx/php 的配置,它允許我在不淹沒伺服器的情況下使用同步。我嘗試使用“靜態”和“按需”配置來生成 php 進程 - 但這沒有產生任何顯著差異。
如果有任何提示或澄清,我將不勝感激。
提前謝謝你
史蒂夫
答案1
這個問題在某種程度上與 Kopano Core 有關。當我一個月前更新到版本 8.6.82 時,所有與執行緒相關的問題都消失了。遲到總比不到好。謝謝大家的建議!