Get the App
SLTechnology News&Howtos  ›  Database  › 

How to add thread memory monitoring to MySQL database

Shulou Source: shulou.com Published: 2022-05-31 18:00:15 12月04日 Update

This article mainly explains "how to add thread memory monitoring to MySQL database". The explanation in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to add thread memory monitoring to MySQL database" together!

Using MySQL I often find that mysqld memory usage will rise very fast (Buffer Pool is allocated by large pages), so that using SWAP, how much memory is used by the Server layer, there is no monitoring mechanism, so the first step I wrote a patch(based on 5.6.6) to monitor how much memory is used by each thread, once mysqld process uses too much memory, to see which threads use more, kill these threads.

The patch looks like this:

This is the effect after patched:

The code can be viewed as patch.

5.6_thread_mem_usage.patch

The basic method is to add callback functions to my_malloc and my_free (@ Taobao Dingqi provides ideas, too handsome), get the THD descriptor that calls my_malloc and my_free functions, and use the newly added malloc_size field in THD to record the application and release of memory. In fact, my_realloc should also update malloc_size, which has not been added yet.

Then use the malloc_usable_size function to determine how much memory the pointer requests when free, and use malloc_size(pointer) to determine above GCC 4.2.

Thank you for reading, the above is "how to add thread memory monitoring to MySQL database" content, after the study of this article, I believe we have a deeper understanding of how to add thread memory monitoring to MySQL database, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Memory threads monitoring data databases functions learning content that is ideas code fields fast situation pointers effects articles methods more mechanisms Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Microsoft Xiaomi Apple vpn