Previously, MySQL had been plagued for a long time because it was resolved after tcmalloc.
The problem is: the website traffic is not high, and the concurrency is between and during peak hours. The CPU usage is high, which fluctuates sharply between 30-80%. You can see that the top command is caused by the MySQL process. At the same time, you can use iostat and SAR to view the iowait value between 20-30.
However, the system can still run stably, and the swap partition usage increases periodically, which directly causes applications to be unable to connect to the database. I don't know if this is a problem with MySQL's swap. When there is no solution, we have to monitor the memory usage frequently and restart the MySQL service when the swap starts to rise. Generally, this cycle is about one week.
Later, I found tcmalloc on the internet, saying that it can make MySQL performance stable under high concurrency, and also said that the MySQL problem is caused by a bug in the malloc memory allocation function, this bug will cause a sharp decline in the Performance of High-concurrency MySQL.
Decide to try.
The system is a 64-bit Redhat Enterprise Linux 5.0. Install another package libunwind in a 64-bit system. Download the tcmalloc package and add it to mysqld_safe after compiling and installing it by default.
Ld_preload = "/usr/local/lib/libtcmalloc. So"
Restart MySQL. There is no way to verify whether tcmalloc is effective. You can only continue to monitor the running status of the system.
After more than a week, you can look at the figure captured from MRTG below:
In the preceding two figures, the first is the CPU and the second is the memory. It can be seen that after tcmalloc is replaced, the CPU usage drops sharply. It has been maintained at around 30%, and currently only accounts for less than 10%. In terms of memory, the original physical memory has been occupied by 100%, and the swap usage fluctuates sharply. The drop point is generally caused by the restart of MySQL. After tcmalloc is replaced, the memory is maintained between 80-90%, and the swap usage is very stable. It can be calculated as zero.
It has been going on for more than a week. It can be said that the effect is quite obvious and very satisfactory. You no longer have to stare at mrtg. Of course, this is the actual situation on my machine. I don't know what other systems are like.
Libunwind: http://www.nongnu.org/libunwind/
Tcmalloc: http://goog-perftools.sourceforge.net/doc/tcmalloc.html
Detailed installation steps:
# Tar zxvf libunwind-0.98.6.tar.gz
# Cd libunwind-0.98.6
#./Configure
# Make
# Make install
# Tar zxvf google-perftools-0.94.1.tar.gz
# Cd Google *
#./Configure
# Make
# Make install
Open the mysqld_safe script (in/usr/bin/mysqld_safe by default)
Add this script file
Ld_preload = "/usr/local/lib/libtcmalloc. So"
# Service MySQL restart