Faster Please

june 8, 2009

This is stuff that the elite may already be using, but I wanted to document it for my own knowledge.  I was trying to speed up my websites, just because speed is good.  I found a few things that I could do and I recently implemented them.

To speed up page creation, I turned on mysql's caching functionality.  I use mysql to drive and, so making mysql faster would make the websites faster.  I edited /etc/my.cnf (for RHEL and CentOS) and added:


Most of the queries for my websites are to build pages and RSS feeds.  This change has helped tremendously because my content does not change very frequently.  In order to see how mysql is doing with query caching and memory usage, I can log into mysql and run:

show status like 'qc%';

The results look kind of like this:

mysql> show status like 'qc%';
| Variable_name           | Value    |
| Qcache_free_blocks      | 2        |
| Qcache_free_memory      | 19791488 |
| Qcache_hits             | 237778   |
| Qcache_inserts          | 6639     |
| Qcache_lowmem_prunes    | 0        |
| Qcache_not_cached       | 31       |
| Qcache_queries_in_cache | 4117     |
| Qcache_total_blocks     | 8246     |
8 rows in set (0.00 sec)

The other thing I did was use Yslow and Page Speed to see what I could improve on both my pages and server.  There was one thing that I did that made an immediate impact on performance:  Turn on gzip/deflate.  It was not hard to do and if you want to, add this to your Apache2 conf:

SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
    no-gzip dont-vary
SetEnvIfNoCase Request_URI \
    \.(?:exe|t?gz|zip|bz2|sit|rar)$ \
    no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

That will compress everything except for images before sending over the network to a client.  It also forces compatibility with older browsers.  This has made load times much quicker because the amount of data hitting the network is less than half as before.  Nice.

There were two other big things done: To turn on etags and mod_expires for image; and add some dimensions to images that load often (mainly the administrative icons for both websites).

This should at least make page loads faster  And on my end, the compression should drop the amount of network traffic for my VPS.