Question

I am experiencing very slow performance on my website due to MySql copying temporary tables to disk.

Increasing tmp_table_size and max_heap_table size solved this issue. The VPS has 1.5 GB RAM. How high can I safely set these variables?

Was it helpful?

Solution

Keep in mind that each thread can have its own temp table in memory (or even multiple temp tables if you have an extremely complex query), so you may have spikes of usage of memory.

If you increase tmp_table_size and max_heap_table_size too much, you risk forcing the mysqld process to swap to virtual memory, which will be no better than your original problem of temp tables going to disk.

You don't need to make tmp_table_size equal to the largest temp table you will ever create, you just need it to be large enough so that the majority of temp tables stay in RAM.

I would recommend increase those config variables modestly, and then monitor SHOW GLOBAL STATUS LIKE 'Created_tmp_disk_tables' to see if the rate of increase of that status indicator is reduced.

You can use a tool like pt-mext to monitor the rate of change of a status variable, or else monitor using Cacti with Percona Monitoring Plugins.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top