Optimising Your Web Stack Performance for Magento

Last modified by Turnkeye.com on Wed, April 6, 2011 02:17
Source|Old Revisions  |  Back To Group

Operating System Configuration

One of the key performance aims is to get as much out of your platform without getting to the point where it is overloaded. The slowest component on modern computers is usually the hard drives. Anything you can do to reduce the need to read or write from the hard drives is ideal. A major cause of disk usage and general slow performance is if your server needs to use swap (or virtual) memory in order to function. Swap memory is used when the physical RAM on your machine becomes full - RAM contents must be ‘swapped’ to disk in order to make room.

The key to avoiding swapping is to configure your system within its limits. If you only have 256MB of RAM, there’s no point allocating half of it to MySQL then expecting your machine to happily run 5 Apache/mod_php processes.

Linux

If you have access-time logging enabled on any of your mysql, web server or cache partitions, try turning it off for a performance boost. If you’re using ext3 or reiserfs there may be faster journal write methods you can use. For more information see http://www.linux.com/feature/116693.

Windows

BSD

OS X

Web Server Configuration

Apache

http://httpd.apache.org/

Apache is a hugely popular web server (the A in LAMP). It can serve PHP sites using mod_php, FastCGI or CGI.

* Enable KeepAlives (see http://httpd.apache.org/docs/2.2/mod/core.html#keepalive and http://www.magentocommerce.com/blog/comments/performance-is-key-notes-on-magentos-performance/)

NginX

NginX is becoming an increasingly popular alternative to Apache and Lighttpd due to its stability, light weight and speed. NginX can server PHP sites using FastCGI or CGI.

Wordpress, Comodo, Hulu, MagentoCommerce and other enterprises choose this platform to run their websites on.

Lighttpd

Lighttpd is another popular lightweight alternative to Apache. Like NginX it is able to run PHP as either FastCGI or CGI. Lighttpd contains a nice tool - spawn-fgi for managing FastCGI processes

LightSpeed

IIS

PHP Configuration

General

* Set memory limit to 64M

mod_php

mod_php for Apache is probably the most popular way to run PHP applications. There are a few down-sides to mod_php though: you’re forced to use Apache’s less efficient prefork MPM and your Apache processes will get large. Serving static files with 32MB+ Apache processes isn’t very efficient.

PHP CGI

When PHP is run as a CGI program the web server spawns a process each time a request is made. This can be less efficient unless your operating system is good at spawning processes quickly. Unlike mod_php, CGI application won’t bloat your Apache, so the processes can remain small for service static files - important for high traffic sites.

PHP FastCGI

When PHP is run as a FastCGI, a number of daemon processes are started and sit waiting for the web server to request them to run PHP code. This avoids the cost of spawning new processes each time in addition to not bloating web server processes. Due to the nature of long-running processes, FastCGI may require some periodic process maintenance. Lighttpd’s spawn-fgi script provides a method to limit the number of requests a single FCGI process is allowed to serve in an attempt to reduce the effect of memory leakage.

Opcode Caches

PHP Opcode caches reduce the processing overhead involved in reading and compiling PHP scripts. They utilise shared memory as a way of storing and re-using compile scripts.

APC

APC http://uk2.php.net/apc is a free PHP opcode cache written by the PHP team and packaged using PECL. APC can be used with mod_php, FastCGI and CGI.

xCache

eAccelerator

ionCube

Zend Cache

MMCache

MySQL/InnoDB Configuration

Most operating systems install a lightweight MySQL configuration by default, a good LAMP server should provide a decent amount of its resources to MySQL. Machines with multiple cores and over 2GB RAM need to be configured carefully to make sure available RAM and cores are being used efficiently.

MySQL

There are some excellent tips in this Magento blog post http://www.magentocommerce.com/blog/comments/performance-is-key-notes-on-magentos-performance/

After your server has been running for at least 48 hours the “MySQL Performance Tuning Primer Script” analyses your server statistics against your configuration and offers guidance: http://www.day32.com/MySQL/

InnoDB

InnoDB (http://www.innodb.com/) is an alternative storage engine which makes use of MySQL’s client/server architecture. Whilst it shares some configuration settings with MyISAM (MySQL’s default storage engine) it has many settings of its own and will compete for server resources with MyISAM. It’s possible to tune MySQL server purely for InnoDB if no MyISAM tables are being used. Magento does however use MyISAM for some small tables so MyISAM is still required.

Multiple MySQL Slaves/Clustering

On larger sites MySQL’s replication functionality can be used to spread SELECT queries across multiple machines. Writes operations will still be run on every server in order to maintain data synchronisation.

Cache Filesystem

Magento uses file caching to store often-used data in an easy to use format. The speed of file caching is directly dependent on speed of the filesystem on which the cache files are being read or written. Again, since hard drives are slow moving this to RAM can really help. Having said that, operating systems will attempt to buffer reads/writes in memory in order to increase speed.

tmpfs

tmpfs is an in-memory filesystem designed to deliver the best possible performance.

Reverse Proxy Configuration

Reverse proxies can be used to speed up the serving of cachable assets such as images, CSS, html and javascript by removing the need to ask the web server to serve them.

Apache mod_proxy/mod_cache

Apache with mod_proxy using the worker MPM is a popular reverse proxy. There are probably also much leighter-weight alternatives. Setting up effect reverse proxies requires a good understanding of the application being proxied and the way in which it is used.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs