2

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

  1. OS: Ubuntu 14.04 server
  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 /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

  1. +/- Cloudflare
  2. optimized php-fpm pm_* values
  3. optimized cache including opcache & memcached, these changes speed up on full page & doc load complete time, but no difference made on TTFB time
  4. +/- nginx logs
  5. adjust gzip level from 1-6
  6. CMS page loads a little bit faster, but still has TTFB 1.815s
  7. A phpinfo() page loads about 40ms
  8. 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
  9. 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
  10. 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
    
huzefam
  • 107
  • 2
Tom
  • 21
  • 1
  • 3
  • 4
    Welcome to Magento. – Michael Hampton Sep 18 '14 at 02:31
  • Same template hosted on joomlart has pretty good page response time e.g. [link](http://jm-kidsland.demo.joomlart.com) has only 91ms wait time [link](http://tools.pingdom.com/fpt/#!/bDJvTn/http://jm-kidsland.demo.joomlart.com/) with a lot of more content than my store, this makes me wondering if I have something configured incorrectly. – Tom Sep 18 '14 at 02:36
  • I agree with Michael.. Magento is horrible but make sure all the caching is enabled in magento also. – Mike Sep 18 '14 at 06:36
  • 2
    There's nothing at all wrong with Magento. It can and will deliver 0.2s TTFB on a properly configured server. Running Magento in an improperly configured server is like moaning that a Ferrari has a poor 0-60 time when you fill the fuel tank with soil. Caching is categorically not necessary and has absolutely nothing to do with performance. The OP just needs a proper hosting provider instead of DIY and needs to profile his code thereafter. – Ben Lessani Sep 30 '15 at 17:22

2 Answers2

0

I've done the following to successfully reduced page load time from 6sec to 1sec by

  1. disable newrelic
  2. disable longview

To be done 1. I am in process of upgrading to 4core 4GB memory system, I will post the result here 2. I am going to consult a full page cache solution.

Tom
  • 21
  • 1
  • 3
0

Magento is exceptionally fast as standard, it will load pages in 0.5s with all caches off and 0.2s with all caches on.

So you don't need strictly to make make Magento faster, you need to remove/change whatever is making it slow.

There's 2 bottlenecks for performance.

  • Poor hosting
  • Poor code

Addressing those is superbly simple,

  • Use a hosting provider that specialises in high performance Magento hosting that can provide store-level support to help you scale and guide you on performance improvement
  • Profile your code, and remove/re-factor poorly performing code

You'll know if your hosting provider is your bottleneck simply by installing a demo store with sample data. If it takes more than 0.5s to load with all the caches off, then there's your issue.

Ben Lessani
  • 5,174
  • 16
  • 37