从Magento + Nginx时间到第一个字节的高等待时间

我有高TTFB时间的问题,特别是发送后的等待时间。

网页testing显示TTFB差不多是4秒。

平托指定等待时间是这里的瓶颈

这里是我的Magento + Nginx服务器的设置,查看testing和configuration的截图http://share.pho.to/#7BuP9

  1. 操作系统:Ubuntu 14.04服务器
  2. nginx的/ 1.4.6
  3. PHP 5.5.9
  4. opcache 7.0.3
  5. memcached的
  6. PHP-FPM
  7. Magento 1.9.0.1
  8. Linode 2GB / 2核心服务器

Nginx服务器configuration

server { server_name dev.magibooks.com; return 301 $scheme://www.dev.magibooks.com$request_uri; } server { listen 80; #listen 443 ssl spdy; #ssl on; #ssl_certificate /etc/nginx/ssl/dev/ssl-dev-unified.crt; #ssl_certificate_key /etc/nginx/ssl/dev/ssl-dev.key; server_name www.dev.magibooks.com; root /var/www/www.dev.magibooks.com/web; ## rewrites dev.magibooks.com to www.dev.magibooks.com #if ($http_host != "www.dev.magibooks.com") { # rewrite ^ $scheme://www.dev.magibooks.com$request_uri permanent; #} location / { index index.html index.php; ## Allow a static html file to be shown first try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler expires 30d; ## Assume all files are cachable #auth_basic "Restricted"; ## Message shown in login window #auth_basic_user_file /var/www/www.dev.magibooks.com/.htpasswd; #autoindex on; } location ~ /\.(eot|otf|ttf|woff)$ { add_header Access-Control-Allow-Origin *; } ## These locations would be hidden by .htaccess normally location /app/ { deny all; } location /includes/ { deny all; } location /lib/ { deny all; } location /media/downloadable/ { deny all; } location /pkginfo/ { deny all; } location /report/config.xml { deny all; } location /var/ { deny all; } location /var/export/ { ## Allow admins only to view export folder auth_basic "Restricted"; ## Message shown in login window auth_basic_user_file /var/www/www.dev.magibooks.com/.htpasswd; ## See /etc/nginx/htpassword autoindex on; } ## Disable .htaccess and other hidden files location ~ /\. { deny all; access_log off; log_not_found off; } location @handler { ## Magento uses a common front handler rewrite / /index.php; } location ~ \.php/ { ## Forward paths like /js/index.php/x.js to relevant handler rewrite ^(.*\.php)/ $1 last; } location ~ \.php$ { ## Execute PHP scripts if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss expires off; ## Do not cache dynamic content #fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param HTTPS $fastcgi_https; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores fastcgi_param MAGE_RUN_TYPE store; include fastcgi_params; ## See /etc/nginx/fastcgi_params } location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { expires 365d; } } 

nginx.conf

 user www-data; worker_processes 2; pid /run/nginx.pid; worker_rlimit_nofile 60000; events { worker_connections 10240; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 2; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; #gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## ## Detect when HTTPS is used map $scheme $fastcgi_https { default off; https on; } client_body_buffer_size 10K; client_header_buffer_size 1k; client_max_body_size 8m; large_client_header_buffers 4 4k; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } 

我试过以下

  1. +/- Cloudflare
  2. 优化的php-fpm pm_ *值
  3. 包括opcache和memcached的优化caching,这些变化加快整个页面和文档加载完成时间,但TTFB时间没有差异
  4. +/- nginx日志
  5. 从1-6调整gzip级别
  6. CMS页面加载速度稍快一点,但仍然有TTFB 1.815s
  7. 一个phpinfo()页面加载大约40ms
  8. 通过追踪access.log,请求总是显示在确切的等待时间后,例如当我刷新dev.magibooks.com时,服务器端需要4秒钟才能看到请求显示access.log
  9. 我怀疑与主页上的产品太多有关,特别是可configuration的产品,我删除了12个产品,TTFB从5秒减less到4秒,但仍然显着高
  10. php慢页面显示如下

     [17-Sep-2014 21:48:45] [pool www] pid 10333 script_filename = /var/www/www.dev.magibooks.com/web/index.php [0x00007fc13eb6f8d8] session_start() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php:125 [0x00007fc13eb6f798] start() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php:168 [0x00007fc13eb6f650] init() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Model/Session/Abstract.php:84 [0x00007fc13eb6f558] init() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Model/Session.php:42 [0x00007fc13eb6f428] __construct() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Model/Config.php:1348 [0x00007fc13eb6f310] getModelInstance() /var/www/www.dev.magibooks.com/web/app/Mage.php:463 [0x00007fc13eb6f1e0] getModel() /var/www/www.dev.magibooks.com/web/app/Mage.php:477 [0x00007fc13eb6f088] getSingleton() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Controller/Varien/Action.php:493 [0x00007fc13eb6ef00] preDispatch() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Adminhtml/Controller/Action.php:160 [0x00007fc13eb6ed08] preDispatch() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Controller/Varien/Action.php:407 [0x00007fc13eb6eaf8] dispatch() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php:250 [0x00007fc13eb6e9a8] match() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Controller/Varien/Front.php:172 [0x00007fc13eb6e850] dispatch() /var/www/www.dev.magibooks.com/web/app/code/core/Mage/Core/Model/App.php:354 [0x00007fc13eb6e6b0] run() /var/www/www.dev.magibooks.com/web/app/Mage.php:684 [0x00007fc13eb6e570] run() /var/www/www.dev.magibooks.com/web/index.php:87 11. minified all js and css 

我已经做了以下成功减less页面加载时间从6秒到1秒通过

  1. 禁用newrelic
  2. 禁用longview

要做的事情1.我正在升级到4core 4GB内存系统,我将在这里发布结果2.我要咨询一个完整的页面caching解决scheme。

Magento标准速度非常快,它将在所有cachingclosures的情况下以0.5秒为单位加载页面,在所有caching打开时以0.2秒为单位加载页面。

所以你不需要严格的使Magento更快,你需要删除/改变任何使它慢。

性能有两个瓶颈。

  • 可怜的托pipe
  • 糟糕的代码

解决这些问题非常简单,

  • 使用托pipe服务提供商,专门从事高性能的Magento托pipe,可以提供商店级支持,以帮助您扩展和指导您的性能改进
  • 分析您的代码,并删除/重新设置性能不佳的代码

您只需通过安装示例数据的演示商店就可以知道您的托pipe提供商是否是您的瓶颈。 如果加载所有的caching需要0.5秒以上,那么这是你的问题。