php 线程(不是进程)不断增加,直到服务器崩溃

php 线程(不是进程)不断增加,直到服务器崩溃

我已经努力解决以下问题一段时间了,非常感谢您的帮助。

由于 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 多行类似的内容

我在跑步

  • 虚拟服务器
  • 8 GB 内存
  • 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 版本时,所有与线程相关的问题都立即消失了。迟做总比不做好。感谢大家的建议!

相关内容