gb
  • gb
  • gb
  • gb
  • gb
  • gb
  • gb
  • gb
  • gb
  • gb
  • gb
-->

Optimizing Magento

This section discusses the various ways of optimizing your server configuration for Magento to deal with large product sets and regular updates from our plug-in. It also includes general best practice.

======== Database configuration ========

The following settings for the ”’my.cnf”’ MySQL configuration file are suitable for a server with 2GB RAM and have been tested with 150,000 products. If you have more RAM, you should look to increase the size of the ”’innodb_buffer_pool_size”’ to increase performance.

local-infile = 1
key_buffer = 384M
max_allowed_packet = 16M
table_cache = 1024
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 16
query_cache_type = 1
query_cache_size = 64M
log_slow_queries=/var/log/mysqld.slowquery.log
max_connections=500
wait_timeout=28000
tmp_table_size = 64M
max_heap_table_size = 64M
innodb_buffer_pool_size = 1408M
innodb_additional_mem_pool_size = 20M

PHP Configuration

Ensure you have the following settings in ”’php.ini”’. You may wish to try increasing memory_limit if you get errors regarding PHP running out of memory

Safe_mode = Off
Memory_limit = 512M

======== Magento Configuration ========

Enable Caching
System > Cache Management > Select All > Enable
This one is an absolute no-brainer and provides one of the best performance enhancements you will get in Magento. This caches the XML layer in Magento, along with some other information, to speed up PHP processing time.

Compilation

System > Tools > Compilation > Run Compilation Process
This option compiles all Magento installation files and creates a single include path. ”’Remember to disable this module before upgrades”’. The compilation process may need to be run again when new files are released.

Disable Logging

System > Configuration > Advanced > Developer > Log Settings > Enabled: No
This is disabled by default, but be sure to double-check it is disabled on production environments, as this setting can drastically slow down your website if enabled.

Enable Flat Catalog/Index

System > Index Management > Enable All
System > Configuration > Catalog > Frontend, set Use Flat Catalog Category/Product to Yes
If you have a large amount of products on your site (>10,000), this update decreases load times on searches, product listings, etc.

Minify JavaScript

Install the Fooman Speedster module – http://www.magentocommerce.com/magento-connect/fooman-speedster.html
The easiest way to minify your JavaScript is to install the Fooman Speedster module. This does everything you need to make sure all of your JavaScript is minified. It also merges your CSS and JavaScript files into one file each

After installing this extension via Magento Connect make sure that /lib/minify/m.php is executable (permissions like 755 on the file itself and the containing folder should work) and /var/minifycache is writeable.

Log Cleaning

Magento creates a lot of logs which can slow performance. You should set up a scheduled task to regularly clean the logs. There are two types which must be culled: files and database entries.

The following commands will delete the files that need to be deleted

rm -rf var/locks/*
php -f downloader/mage.php clear-cache
rm -rf downloader/pearlib/cache/*
rm -rf downloader/pearlib/download/*
rm -rf var/cache/*
rm -rf var/session/*
rm -rf var/report/*
rm -rf var/tmp/*

To clean the database, the shell utility log.php can be configured as a cron job or run manually to clean on-the-fly.

From the Magento root directory, type:
php -f shell/log.php clean
the –days switch can be used to specify how many days back to save.

The following tables are truncated:
log_customer
log_visitor
log_visitor_info
log_url
log_url_info
log_quote
report_viewed_product_index
report_compared_product_index
report_event
catalog_compare_item

== Server Configuration ==

Instal NgInx==

Nginx is significantly faster than Apache. We have tested our plug-in with it and it works fine

Enable Gzip

This is a must-have tweak. It decreases page size by over 30%. Make sure to enable the deflate module in your Apache configuration, then comment out the appropriate lines in the mod_deflate.c directive of your ~/.htaccess file.
Many instances of Linux will have this enabled by default

## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
# Netscape 4.x has some problems…
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don’t compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary

Install APC

Install APC with the command line pecl install apc
Also add the following cache handle to your app/etc/local.xml configuration


apc
yourdomain_com_

This should result in an increase of around 30% in page load speed

Enable KeepAlive’s

Add the following lines to your Apache configuration file

KeepAlive On
KeepAliveTimeout 2

Apache KeepAlive keeps the TCP connection open between the client and the server, allowing multiple requests to be served over the same connection. This removes some overhead with sites serving up a lot of concurrent HTTP requests. Make sure you have plenty of memory if you do this as each connection consumes resources.

Disable open_basedir

Add the following line to your Apache configuration file

php_admin_value open_basedir none

The open_basedir parameter is a security feature that restricts filesystem lookups, but can hurt performance on applications with a large filesystem footprint like Magento.

Let us know if we missed anything...

Leave a Comment

You must be logged in to post a comment.