Be seen. Boost your question’s priority for more expert views and faster solutions
In this article, we’ll look at how using thread_statistics can cause high memory usage.
I was recently working on a high memory usage issue for one of our clients, and made some interesting discoveries: high memory usage with no bounds. It was really tricky to diagnose.
Below, I am going to show you how to identify that having thread_statistics enabled causes high memory usage on busy systems with many threads.
I had a server with 55.0G of available memory. Percona Server for MySQL version:
So in our case, this shouldn’t be more than ~12.5G.
After MySQL Server has been restarted, it allocated about 7G. After running for a week, it reached 44G:
I checked everything that could be related to the high memory usage (for example, operating system settings such as Transparent Huge Pages (THP), etc.). But I still didn’t find the cause (THP was disabled on the server). I asked my teammates if they had any ideas.
User Statistics adds several
INFORMATION_SCHEMAtables, several commands, and theuserstat variable. The tables and commands can be used to better understand different server activity, and to identify the different load sources. Check out the documentation for more information.
Since we saw many threads running, it was a good option to verify this as the cause of the issue.
I decided to apply some calculations, and the following test cases to verify the cause:
Let’s calculate how many rows we have in this table at this time, and check once again in an hour:As we can see, memory usage drops to the approximate value of 2G that we had calculated earlier!
That was the root cause of the high memory usage in this case.
User Statistics (basically Thread_Statistics) is a great feature that allows us to identify load sources and better understand server activity. At the same time, though, it can be dangerous (from the memory usage point of view) to use as a permanent monitoring solution due to no limitations on memory usage.
As a reminder, thread_statistics is NOT enabled by default when you enable User_Statistics. If you have enabled Thread_Statistics for monitoring purposes, please don’t forget to pay attention to it.
As a next step, we are considering submitting a feature request to implement some default limits that can prevent Out of Memory issues on busy systems.
|How to save your database to Dropbox (and how to restore it) from within a Cordova application - Android only (part 2)||308|
|How to save your database to Dropbox (and how to restore it) from within a Cordova application - Android only (part 3)||336|
|Stellar SQL Database Toolkit is Best Solution for All SQL Database Issues||619|
|How to Fix Error: Unable to mount database (HR=0x80004005, EC=-543)||243|