Web applications developers such as myself often have a hard time keeping up with everything that’s going on. There’s always some new programming or scripting language, new standards, new browsers, new technologies, new paradigms, new social networks, and on and on. Every day, something new happens. The end result of all of this always ends up being very similar: people demand faster applications that deal with ever-increasing amounts of data which end up putting massive stress on the server architecture.
As we toil to improve the performance of the applications and their snappy response times, it becomes easy to forget about how we can tweak settings on a low level to provide massive speed improvements on the front-end. For example, most people don’t know that you can configure MySQL to take better advantage of the resources that the server has available.
By default, MySQL is configured to consume a relatively limited amount of memory resources. Start giving MySQL more memory to work with, and your application’s performance can improve greatly.
Unfortunately, I’m not a MySQL configuration guru. I’ve never read through the source code or any low-level technical documents about how it functions. So most of the configurations options are a complete mystery to me, and I don’t know if changing a specific option could benefit me at all.
Fortunately, I don’t have to be a MySQL configuration guru to get better performance. There is an amazing tool created by Matthew Montgomery called the MySQL performance tuning primer script.
Matthew Montgomery’s script does an amazing job of giving me information about how my MySQL configuration may be inappropriate for the queries being executed and provides information about what variables to modify in order to better optimize my configuration. For example, the “TEMP TABLES” section of the output tells me the following:
TEMP TABLES Current max_heap_table_size = 512 M Current tmp_table_size = 512 M Of 1684 temp tables, 10% were created on disk Effective in-memory tmp_table_size is limited to max_heap_table_size. Created disk tmp tables ratio seems fine
Previously, I had my
tmp_table_size variables set to default settings and had up to 60% of my temp tables created on disk. As much as possible, temp tables should be created in memory to reduce the performance penalty of using the disk for random access to such data rather than memory which is much faster.
Now this doesn’t mean that you should set your variables to the same settings as I have. The server that this is running on is dedicated to running a dispatching system that has many tables containing hundreds of thousands of rows each. The value of the script is that it will help you tailor your settings to best use your hardware without having MySQL consume too many resources that other processes (such as you web server) could use.
The script is provided as a standard Linux shell script. Download the script into a folder of your choosing and run
Good luck with your MySQL optimization. I hope that you get as great of results as I have. Keep in mind that if your table structures and queries are inefficient to begin with, that configuration optimization can only do so much to improve the performance.
- Tuning LAMP systems, Part 3: Tuning your MySQL server
This is a great read that should help most novice database administrators understand some of the basics about tuning their database’s performance.
- MySQL Performance Blog
A blog by the authors of High Performance MySQL (also highly recommended). This blog is updated frequently with great tips that will help you develop higher-performance apps.
Did I help you?