MySQL Server becomes stable after tcmalloc (Linux)

Source: Internet
Author: User
Tags mrtg
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.