30.06.2016 Views

Magento Site Performance Optimization

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tuning, Scaling, and Replicating MySQL<br />

We can easily bring proof of this stress imposed on MySQL by <strong>Magento</strong> to the<br />

forefront. First, we have to delete the cache file of <strong>Magento</strong>, using the following<br />

command, in order to be sure that all the data will be fetched from the database:<br />

$ sudo rm –R /var/www/magento-optimization/var/cache/mage--*<br />

Be sure to adapt the path to your installation. If the used path matches the different<br />

installation steps discussed in the previous chapter, then we can activate the logging<br />

mechanisms of MySQL. This mechanism is, by definition, performance killer as they<br />

will write into a file every single operation our database engine does. Therefore,<br />

be sure to deactivate it in a production environment. To do so, you have to edit the<br />

main configuration file of MySQL with the following command:<br />

$ sudo nano /etc/mysql/my.cnf<br />

Look for #general_log_file in line 72 and uncomment it (remove the "#"). You can<br />

now restart your MySQL server for the new configuration to be loaded by using the<br />

following command:<br />

$ sudo /etc/init.d/mysql restart<br />

To be sure that we have sufficient data in our logging file, we first request the home<br />

page of our <strong>Magento</strong> and then the usual furniture category. The generated logging<br />

file is 352 lines long and is characterized by the following values:<br />

• 179 selects<br />

• 2 updates (log visitor)<br />

• 4 inserts<br />

• 0 delete<br />

Some of the requests are very simple and we can assume that they do not cost too<br />

much to be completed. However, some of them are composed of many jointure and<br />

imbricated select. Here is an example of a fairly simple query and a much more<br />

complex query:<br />

select count(*) into @discard from 'information_schema'.'EVENTS';<br />

In the preceding code, we have a simple count on the Events table. The following<br />

one, however, has five inner jointures and many count and order operations:<br />

SELECT 'attr_table'.* FROM 'catalog_category_entity_varchar' AS<br />

'attr_table'<br />

INNER JOIN 'eav_entity_attribute' AS 'set_table' ON<br />

attr_table.attribute_id = set_table.attribute_id AND<br />

[ 40 ]<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!