9 Methods to Speed Up Magento – A Guide to Making Magento Faster
Methods To Speed Up Magento
Hi Guys,
Ok. Figuring out how to get this puppy purring over the last few days.
Thought I would post a ‘How To Speed up Magento’ Guide based on what I have found out. And maybe others can chip in afterwards with their top tips, and we can turn this into a one-stop thread to getting Magento installs working nice and fast 
1/ Install Fooman Speedster
This one made a massive difference to page loads for the first site I am testing.
http://www.magentocommerce.com/extension/457/fooman-speedster
2/ Enable Gzip Compression in .htaccess
http://www.magentocommerce.com/boards/viewthread/7100/
To do this, uncomment this part in the .htacess: (Line 52)
#php_flag zlib.output_compression on
(ie Remove the # save and reupload)
(Next 4 are from – http://www.magentocommerce.com/blog/comments/performance-is-key-notes-on-magentos-performance/)
3/ Install APC or Xcache
APC – http://pecl.php.net/package/APC
Xcache – http://xcache.lighttpd.net/
Looking at benchmarks and folks comments, it seems to be a toss of coin which one to go for.
I will probably go for APC on balance.
Will be asking my host to install this.
Ok. My host installed it. And further to Discovery posting below, thought I would add that in here to the main body. Discovery pointed out that thread here had extra tips once APC had been installed: http://www.magentocommerce.com/boards/viewthread/9882/
Essentially, after APC has been installed, you locate the local.xml file in the install. (Mine was here – /home/yoursitename/public_html/app/etc/local.xml
You then add the following code to just below:
<global>
<cache>
<backend>apc</backend>
<prefix>alphanumeric</prefix>
</cache>
I have to say that I actually have installed APC, and then tried this, but that it actually slowed down my server. Response times went up from about 2 seconds to 3 seconds.
Your mileage may however vary, so give it a go 
4/ “Make sure your Apache configuration has KeepAlives enabled. KeepAlives are a trick where multiple HTTP requests can be funneled through a single TCP connection. Since the setup of each TCP connection incurs additional time, this can significantly reduce the time it takes to download all the files (HTML, JavaScript, images) for a website.”
No idea what this is. And there is no further mention of it anywhere. So I will ask my host to enable it. Would be good to have some more info on this, if anyone knows what it is?
5/”Modify the configuration for your MySQL server to take better advantage of your server’s RAM. Most Linux distributions provide a conservative MySQL package out of the box to ensure it will run on a wide array of hardware configurations. If you have ample RAM (eg, 1gb or more), then you may want to try tweaking the configuration. An example my.cnf is below, though you will want to consult the MySQL documentation for a complete list of configuration directives and recommended settings.”
They have a list of settings there for my.cnf as follows:
key_buffer = 512M
max_allowed_packet = 64M
table_cache = 512
sort_buffer_size = 4m
read_buffer_size = 4m
read_rnd_buffer_size = 2m
myisam_sort_buffer_size = 64m
tmp_table_size = 128m
query_cache_size = 96m
query_cache_type = 1
thread_cache_size = 8
max_connections = 400
wait_timeout = 300
Again, get your host to do it, (which is what I will be doing
) or figure it out.
6/ “Use a memory-based filesystem for Magento’s var directory. Magento makes extensive use of file-based storage for caching and session storage. The slowest component in a server is the hard drive, so if you use a memory-based filesystem such as tmpfs, you can save all those extra disk IO cycles by storing these temporary files in memory instead of storing them on your slow hard drive.”
Ok. Rather unhelpfully, there is no mention anywhere of how to do this.
So, if someone could post a step by step on this, then that would be useful.
7/ This thread here – http://www.magentocommerce.com/boards/viewthread/5366/P60/ – Includes a post from a Server Admin at Rackspace who had experience optimizing for Magento
The two that jumped out at me were:
a/ First off, I made some changes to your system, I increased the APC.shm.size to 128 This will allow more data to be cached by apc, in theory it’ll store more data.
(This sounds like it is linked to APC above – So maybe install APC first before doing this
)
8/ From thread above:
“I also made some changes to the vhost.conf file for the shop site, historically disabling open_basedir allows magento to work slightly better.”
No idea what this is. Any guru’s care to comment? A step by step would be useful from someone if you know how to do it.
(Continued in next post because I ran out of characters…
)
Speed up your Cache files
Magento makes extensive use of file-based storage for caching and session storage. The slowest component in a server is the hard drive, so if you use a memory-based file system such as tmpfs, you can save all those extra disk IO cycles by storing these temporary files in memory instead of storing them on your slow hard drive.
Let´s do this with tmpfs
Let’s say your Magento install is at /var/www/domain.com/ so your cache and session directories are /var/www/domain.com/var/cache/ and /var/www/domain.com/var/session/ For cache we will allocate a max of 256MB RAM and for sessions 64MB RAM. It is important to give access to everyone (e.g your webserver Apache)
mount -t tmpfs -o size=256M,mode=0744 tmpfs /var/www/domain.com/var/cache/
mount -t tmpfs -o size=64M,mode=0744 tmpfs /var/www/domain.com/var/session/
Now it might be a good idea to restore these volumes each time your server boots. Just add the following lines to your /etc/fstab:
tmpfs /var/www/domain.com/var/cache/ tmpfs size=256,mode=0744 0 0
tmpfs /var/www/domain.com/var/session/ tmpfs size=64,mode=0744 0 0
Please note, your tmpfs is temporary in the sense that nothing will be created on your hard drive. If you reboot, everything in tmpfs will be lost.
in /etc/fstab
tmpfs /var/www/domain.com/var/cache/ tmpfs size=256M,mode=0744,uid=www-data,gid=www-data 0 0
for me, adding ‘M’ to the end of the size option was the difference btw being this working and not working. also, i added a user and group.
one more thing, sessions in magento are typically < 2k, admin sessions are about 800k. you’ll want to take that into account when you’re setting the size. assuming no admin sessions, 64M is only ~ 38,000 sessions, and if your store is doing a healthy 10k daily uniques, you’ll start getting errors on day 3.
to your crontab, add something like:
15 3 * * * find /*mypath*/var/session/ -mtime +1 -exec sudo rm {} +
this will execute daily and remove all session files older than one day.
Hi,
I tried the above tmpfs cache solution:
mount -t tmpfs -o size=256M,mode=0744 tmpfs /var/www/domain.com/var/cache/
mount -t tmpfs -o size=64M,mode=0744 tmpfs /var/www/domain.com/var/session/
Magento stopped working. Does anybody have an idea why? See here:
http://www.moress-charms.com/order/
Thanks!
We have developed a Magento page caching module that reduces page response times to lower than half a second. You can see our module working at zumiez.com and redmarblesteaks.com
Check us out at http://store.delorumcommerce.com
Take a look at Magento Booster extension, it significanly speeds up the performance of your Magento store: http://www.aitoc.com/en/magento_booster.html
Greate posts, It’s just for me. my magento site is very slowly!