【问题标题】:nginx + php-fpm configuration. Server stallsnginx + php-fpm 配置。服务器停顿
【发布时间】:2012-12-23 15:14:54
【问题描述】:

每天运行 140 000 次页面浏览量的服务器(分析)。 每个 php-fpm 进程大约需要 10-12M。
服务器有 10G 内存,mysql 有 1.2G-1.6G

配置如下:

nginx

user  nginx;
worker_processes  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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;
     access_log off;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  10;

    client_max_body_size 20M;

        server_tokens off;

    include /etc/nginx/conf.d/*.conf;
}

php-fpm 像这样:

listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = webadmin
group = webadmin
pm = dynamic
pm.max_children = 900
pm.start_servers = 900
pm.min_spare_servers = 200
pm.max_spare_servers = 900
pm.max_requests = 500
chdir = /

通常情况下,服务器可以在 500 个同时用户的情况下正常运行(同样,实时谷歌分析用于获得此估计值)但有时会在用户不是很多(75-100 个同时用户)时停止。

配置由我信任的 ISP 完成,但我仍然想知道配置是否有意义。

【问题讨论】:

    标签: configuration nginx php


    【解决方案1】:

    我并不是说这是最好的设置,但它对我们有用。

    我使用我们的 nginx 设置更新的一些内容是:

    worker_connections,我相信浏览器会为每个请求打开两个连接,因此从技术上讲,每个请求没有 1024 个可用连接,而您有 512 个可用连接,因此可以将其更改为 2048。

    我还将 错误日志 文件参数更改为“info”,仅当您考虑写入时间以保持 I/O 低时,所以我将其从“警告”更改为“信息” .

    如果您想保留 访问日志,可能会缩减它添加的整个日志。

    可能值得查看您的主 nginx.conf 以及您可能有配置被此文件覆盖并被设置回默认值。

    我从一个大清单中做了两件小事,但是这篇文章很棒 - link

    【讨论】:

    • 感谢 OliverBS。我特别想知道 php-fpm 配置,因为 php-fpm 进程会吃掉我们所有的内存。 max_children = 900 聪明吗?
    • 嘿,我正在运行 ubuntu,所以可能不一样,但我通过 apt 安装了 ab,然后安装了 htop,这样我就可以看到内存使用率上升,然后我让 ab 发送大量请求并在我设置 max_children 以及等待接收进程的孩子时跟踪内存使用情况,我会说获得一些基准测试工具并对其进行测试,直到您获得完美的设置。这有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 2014-01-25
    • 1970-01-01
    • 2013-06-13
    • 2016-11-28
    • 2017-05-12
    • 2011-07-16
    相关资源
    最近更新 更多