A week ago I started to think about optimizing performance of my web server because there was quite high load on my server- about constant 30% CPU usage.
The biggest problem was with MySQL which had about 700 queries per second (mostly from my old mobile statistics portal: statistics.infowap.info). So I removed queries which were not essential, optimized some indexes, combined some queries by joining them and I got about 40% less CPU usage for MySQL and about 400 queries per second. Of course big thanks go to these two fantastic resources for optimizing SQL queries:
http://use-the-index-luke.com/ found this resource thanks to Reddit
http://www.mysqlperformanceblog.com/ but this while Googling about MySQL…
I am not MySQL guru so I didn’t try to optimize my SQL server even further but I still got quite high CPU load. And now I started to think how I can optimize Apache2 web server.
Some of the things I done:
AllowOverride All changed to AllowOverride None and htaccess Rewrites moved from .htaccess to Apache configuration files
Disabled unnecessary Apache modules, for example, mod_status, mod_info, mod_speling, mod_proxy_balancer, mod_proxy_ftp, mod_proxy_connect, mod_dav_svn, mod_wsgi
KeepAlive On, KeepAliveTimeout 2 gave me the best performance.
But still I was not satisfied so I got my hands onto PHP optimization. Different virtual hosts needed different PHP modules but every module was enabled for every virtual host (I have different php.ini for every host). I disabled most of php modules globally from /etc/php.d/ and enabled php extensions per virtualhost basis and results were impressive! I got about the same performance increase as by optimizing indexes and MySQL configuration.
In summary I got huge performance increase. Before I had about 30% load on all 4 CPU cores but now I have 10-15% CPU usage for four CPU cores. basically I could run all my websites on much “weaker” hardware and maybe even I can move back to VPS solutions now instead of using dedicated server with all problems associated with it 🙂