2013-12-22

Recently I had to work with a eCommerce web application which sells products by showing it’s images. This will be hosted on a heavy duty server where there are many admins/suppliers are adding products in back end to this system. This app uses AWS service.

After spending/testing in Goggling few days and hours in b, I log eating got lots of information to boost the site performance. Simply you can not run the Magento application on 2GB RAM. Lots of links have created a confusion where do I start. Obviously only a programmer can identify the application area where performance can be drastically improved and only Sys-Admin can say how to make it faster in Internet cloud sadly.

So definitely an admin requires a back end support to do this . Before touching the config. you need to check te existing site performance with http://gtmetrix.com/

The Approach I had taken,

1. Use cloudfront CDN service to distribute the images under cache folder. Expiry headers and Cache expiry time meta data are set with each S3 image objects while uploading. Synchronizing “cache” folder from media folder to CDN through a bash script.

2. Install and configure Varnish cache.

3. Use Turpentine (Magento plugins for Varnish Cache ) to create/manage ACL for varnish config file.

3. Use High CPU capacity instance (C3.large) which driven on SSD drive comes up with moderate I/O. Cost will be $109/Mon.

4. Set expiry headers and enabled gzip compression for JS/CSS scripts those are serve from web server. Merging jss to a single file a good idea. But loading them all on landing page is a bad idea. So landing page should be load fast and use the js/css only required to load that page.

5. Use dedicated server for Database. I uses RDS service for MySQL database.

6. Optimize Apache settings for Magento.

1. Use cloudfront CDN service to distribute the images under cache folder.

I have created new s3 bucket and then formed cloudfront service associated with it. Also create new CNAME for accessing CDN url. like media.mydomain.com. Also I set a cronjob to synchronize the files under “media/catalog/product/cache” as well as /home/youspred/public_html/media/avatar/. Based on the discussion with devop, I noticed thatonly cache folder need to move to CDN since all the files are displayed from it.

Here is my S3 command which I set for mirroring cache folder to Amazon S3 on every 10 mts interval. Also I did the same for “avatar” folder too using the same script file.

/usr/bin/s3cmd  sync  --recursive  setacl --acl-public --recursive  --add-header="Expires:`date -u +"%a, %d %b %Y %H:%M:%S GMT" --date "+4 years"`" --add-header='Cache-Control:max-age=31536000, public'  /home/domain/public_html/media/catalog/product/cache/ s3://domain.com/catalog/product/cache/

2. Install and configure Varnish cache

This is the major brake point of boosting the site performance I believe. I installed varnish simpy using yum command.

[root@mail ]# yum install varnish

Dependencies Resolved

==================================================================================================================================================

 Package                             Arch                        Version                                Repository                           Size

==================================================================================================================================================

Installing:

 varnish                             i686                        3.0.3-1.3.amzn1                        amzn-updates                        348 k

Installing for dependencies:

 jemalloc                            i686                        3.0.0-2.3.amzn1                        amzn-main                            89 k

 varnish-libs                        i686                        3.0.3-1.3.amzn1                        amzn-updates                        171 k

Transaction Summary

==================================================================================================================================================

Install       3 Package(s)

Upgrade       0 Package(s)

Total download size: 607 k

Installed size: 1.3 M

Is this ok [y/N]:

Configuration files for Varnish

1. /etc/varnish/default.vcl (cache control file)

2. /etc/sysconfig/varnish ( varnish server config file)

Configure Varnish for your environment,

a. Switch Apache to listen on 8000 port

First you need to change the Apache Lister port and NameVirtualHost entry to become another port. Say 8000

After changing the settings my httpd.conf file will have the following entry.

a.NameVirtualHost *:8000

b. Listen *:8000

c. Updated VirtaulHost config file

Note : Ensure the your site displayed correctly on the port 8000

  <VirtualHost *:8000>

ServerName uat.domain.com

DocumentRoot /home/domain/public_html

DirectoryIndex index.php index.html

<Directory /home/domain/public_html/>

Options -Indexes IncludesNOEXEC FollowSymLinks SymLinksIfOwnerMatch

 AllowOverride All

</Directory>

</VirtualHost>

2. Update the Varnish config settings

Now you need to update the varnish config file (/etc/sysconfig/varnish) and change the following variables.

VARNISH_LISTEN_ADDRESS=0.0.0.0

VARNISH_LISTEN_PORT=80

3. Restarting Apache and Varnish

[root@rc-026 ~]# service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

[root@sf-qa01 ~]# service varnish restart

Stopping Varnish Cache:                                    [  OK  ]

Starting Varnish Cache:                                    [  OK  ]

[root@sf-qa01 ~]#

b. Installing Turpentine Magento plugin

This is a very good magento plug-ins which is designing Varnish ACL list. ie what are the urls to be cached or not cached. Especially anything under “/admin” shall not be cached by Varnish. Once you can able to install this plug-in on Magento, you can see a menu “Turpentine” under system main menu.

You can see 2 main menu under this plugin, Varnish options and Cache options.

Varnish options : Information about the Varnish server, admin port and secret key. you can see the secret key under “/etc/varnish/secret” file.



Cache Options : Information about back end server port and adjusting ACL parameters and timed out values.

Cool ! I see whenever we change varnish options, it will create a file “default.vcl” under var folder. So what I did was I have created a symbolic link to this file from original config location to become Varnish to use the latest setting set by the Turpentine plug-ins.

[root@sf-host1 ~]#mv /etc/varnish/default.vcl /etc/varnish/default.vcl-bk

[root@sf-host1 ~]#ln -s /home/domain.com/public-html/var/default.vcl /etc/varnish/default.vcl

cat /dev/null > /var/lib/varnish/varnish_storage.bin

[root@sf-host1 ~]# service varnish restart

Author: Liju Mathew
Visit Liju's Website - Email Liju
I'm Liju, one linux enthusiastic who have been playing with Linux for more than 7 years. I'm curious about to read blog, learning and implementing new technologies from my personal experience. Like to be play with burning head on busy schedule :-) This is a bookmark of all challenges that I'd faced which would be helpful to others sometimes as I'd learn it from the same way :-)

Nothing more, I have to go miles, before I sleep

Show more