【问题标题】:Slow Nginx + PHP-FPM during High Traffic on Magento EnterpriseMagento Enterprise 高流量期间缓慢的 Nginx + PHP-FPM
【发布时间】:2012-10-14 19:29:45
【问题描述】:

我们将 Nginx 与 PHP-FPM 一起用于 Magento Enterprise Edition 1.12

一切正常,但是当我们的访问者超过 150 人时,速度就会下降。在此期间,我们注意到 CPU 利用率为 10%,空闲内存超过 40%。

服务器配置:

CPU 2 x Intel Xeon E5-2680 2.7 GHz 8 Cores 16 Threads 8 GT/s (w H/T) 
RAM 8GB x 8 = 64 GB Total 
NIC 1G connected to Firewall
NIC 1G connected to DB server running percona MySQL

配置:nginx.conf

user nginx;
worker_processes 32;

error_log  /var/log/nginx/error.log;

pid        /var/run/nginx.pid;

events {
worker_connections  1024;
# multi_accept on;
}

http {
include       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       off;
autoindex         off;
keepalive_timeout 10;

## detect https
map $scheme $fastcgi_https {
    default off;
    https on;
}
# Store FastCGI Cached (microcaching) of PHP pages in our tmpfs ramdisk
fastcgi_cache_path /tmpfs/nginx levels=1:2 keys_zone=mage:5m max_size=1g inactive=1h;
open_file_cache max=10000 inactive=30m;
open_file_cache_valid 10m;
open_file_cache_min_uses 2;
open_file_cache_errors on;
proxy_read_timeout 10;

upstream phpfpm {
    server localhost:9000;
}

gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_min_length  1100;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/x-javascript text/xml application/xml
application/xml+rss text/javascript;
# Some version of IE 6 don't handle compression well on some mime-types, so just disable for them
gzip_disable "MSIE [1-6].(?!.*SV1)";
# Set a vary header so downstream proxies don't send cached gzipped content to IE6
gzip_vary on;

# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;

# Health-check server
server {
    listen       80;
    server_name  localhost;
    charset      utf-8;
    access_log off;
    location / {
        root   share/nginx/html;
        index  index.html index.htm;

    }

    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   share/nginx/html;
    }

    }

}

配置 PHP-FPM.conf

[global]
pid = /var/run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm/error.log
[www]
listen = 127.0.0.1:9000
listen.backlog = 65536
listen.allowed_clients = 127.0.0.1
user = nginx
group = nginx
request_terminate_timeout = 600
pm = static
pm.max_children = 846
#pm.start_servers = 200
#pm.min_spare_servers = 200
#pm.max_spare_servers = 200
pm.max_requests = 10000
slowlog = /var/log/php-fpm/www-slow.log

配置fastcgi.conf

#fastcgi_set_header "Set-Cookie";
#if ($http_cookie != "X-Store=1" ) {
#  add_header Set-Cookie "X-Store=1; path=/";
#}

## Catch 404s that try_files miss
if (!-e $request_filename) { rewrite / /index.php last; }

## Blacklist media location from fcgi
if ($uri !~ "^/(media|skin|js)/") {
fastcgi_pass phpfpm;
}

## Tell the upstream who is making the request
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;

# Ensure PHP knows when we use HTTPS
fastcgi_param  HTTPS           $fastcgi_https;

## Fcgi Settings
include                        fastcgi_params;
fastcgi_connect_timeout        60;
fastcgi_send_timeout           60;
fastcgi_read_timeout           300;
fastcgi_buffer_size            4k;
fastcgi_buffers 512            4k;
fastcgi_busy_buffers_size      8k;
fastcgi_temp_file_write_size   256k;
fastcgi_intercept_errors       off;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME     $fastcgi_script_name;
# nginx will buffer objects to disk that are too large for the buffers above
fastcgi_temp_path              /tmpfs/nginx/tmp 1 2;
#fastcgi_keep_conn              on; # NGINX 1.1.14
expires                        off; ## Do not cache dynamic content

顶部

top - 13:24:45 up  5:58,  1 user,  load average: 0.88, 0.70, 0.71
Tasks: 1465 total,   3 running, 1462 sleeping,   0 stopped,   0 zombie
Cpu(s):  4.1%us,  0.1%sy,  0.0%ni, 95.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  65942708k total, 38795452k used, 27147256k free,   213844k buffers
Swap:  8388600k total,        0k used,  8388600k free,  1263300k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
3300 nginx     20   0 1404m 169m 127m S 28.3  0.3   0:30.33 php-fpm
4165 nginx     20   0 1401m 156m 117m S 26.0  0.2   0:30.17 php-fpm
4072 nginx     20   0 1410m 163m 118m S 22.7  0.3   0:27.75 php-fpm
3710 nginx     20   0 1402m 163m 123m R 12.8  0.3   0:32.39 php-fpm
3578 nginx     20   0 1401m 157m 118m S 11.9  0.2   0:27.39 php-fpm

我们正在使用 magento 企业并使用全页缓存。 APC 也已安装并处于活动状态。

问题:在高流量时变得非常慢。

史蒂夫

【问题讨论】:

  • CPU 使用率看起来超过 10%。 Magento 不是轻量级软件,我并不惊讶 CPU 正在努力处理整个系统的每个 PHP 请求。您是否使用 XDebug 分析了应用程序以查看哪些部分占用的时间/内存最多?另外,我会使用htop 而不是top
  • 我正在安装 XDebug。所以你看不出 Nginx conf 有什么问题?
  • 我们在网站上有 70 位活跃访问者。当我们对 250 个访问者的机器进行压力测试时,CPU 会飙升至 12%。
  • 你确定是这台机器的问题吗?通常,数据库节点是第一个因向其抛出过多查询而开始减速的。假设每秒 150 个用户 x 每页 15 个查询 = 每秒 2,250 个查询。如果 MySQL 数据库没有变慢,请查看 1GB 网络是否已饱和。
  • 无论如何,您需要更好的日志记录设置,以便系统可以告诉问题是什么。在线查看 MySQL 调整脚本,启用 MySQL 慢查询日志,在您的 本地 开发机器上安装 XDebug(因为它会减慢速度)并查看应用程序的哪些部分最慢或发送最多查询。检查你的 nginx 和 PHP-FPM 日志。

标签: magento nginx


【解决方案1】:

我在这里回答得相当彻底……

NGINX-FPM configuration settings for magento

简单总结一下,

您要问的是我认为每个人都难以使用的东西 nginx 和 php fpm... 从中获得更多性能。我的意思是,我们 如果我们不尝试获取该站点,可以只使用 apache 和 php 性能提升对吗?有很多答案,意见和 案例库解决方案...但是,问题确实是Magento,而不是服务器的配置。 Magento 对于任何环境来说都太大太重了。 Magento 托管是一项非常乏味且令人不快的任务。

【讨论】:

    猜你喜欢
    • 2012-08-30
    • 1970-01-01
    • 2017-04-11
    • 2016-05-25
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多