MySQL gradually slows down until server reboot

MySQLperformance

The performance of pages on my site that access my mysql database slows down over time until I reboot my server. (Static pages are not affected.) Restarting mysqld itself doesn't help, but rebooting the entire server helps. I've tried various MySQL performance tweaks and enabled caching, none of which helped.

It's initially very fast, but after a few days becomes much slower, and it eventually becomes unbearably slow. Any mysql operations that I run from the command line are perfectly fine, including connecting to mysql, connecting to a database, and running queries. The slow queries log doesn't show anything abnormal. But any page on my site that connects with mysql runs very slowly.

If I reboot my server, everything runs fast again, until it slows down again.

my.cnf:

max_connections = 500
query_cache_size = 10M
tmp_table_size = 16M
max_heap_table_size = 16M
thread_cache_size = 4
innodb_buffer_pool_size = 7G
symbolic-links=0

top, server up 3 days:

top-3days

top, server up 5 mins after reboot:
top-5min

What are some steps I should take to isolate and fix this problem?

Best Answer

Sounds like you're swapping badly.

Your problem could be double buffering. Try adding this to your my.cnf (and restarting your mysql server, obviously):

innodb_flush_method = O_DIRECT

And reduce your swapiness at the OS level, like so:

echo 0 > /proc/sys/vm/swappiness