I am having issue with high TTFB time, especially wait time after send.
Webpagetest shows the TTFB is almost 4 seconds.
Pingtom specifies the wait time is the bottleneck here
Here is my setup for Magento + Nginx server, see screenshots for test and configuration http://share.pho.to/#7BuP9
- OS: Ubuntu 14.04 server
- nginx/1.4.6
- PHP 5.5.9
- opcache 7.0.3
- memcached
- PHP-FPM
- Magento 1.9.0.1
- Linode 2GB /2Core Server
Nginx server config
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/*;
}
I've tried the following
- +/- Cloudflare
- optimized php-fpm pm_* values
- optimized cache including opcache & memcached, these changes speed up on full page & doc load complete time, but no difference made on TTFB time
- +/- nginx logs
- adjust gzip level from 1-6
- CMS page loads a little bit faster, but still has TTFB 1.815s
- A phpinfo() page loads about 40ms
- By tailing the access.log, the request always show up after exact wait time, e.g. when I refresh dev.magibooks.com, it takes 4 seconds on server side to see request showing up on access.log
- I suspect something to do with too many products on homepage, especially configurable products, I removed 12 products, TTFB reduced from 5 seconds to 4 seconds, but still significant high
php slow page shows the following
[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