Static compilation of TCMalloc to MySQL

Source: Internet
Author: User
The content of this article complies with the CC copyright protocol and can be reproduced at will. However, the original source and author information of the article and copyright statement URL must be indicated in hyperlink form: www.penglixun.comtechdatabasestatic_compile_mysql_with_tcmalloc.html malloc function performance, most people write C in Linux

The content of this article complies with the CC copyright protocol, can be reproduced at will, but must be indicated in the form of Hyperlink original source and author information and copyright statement URL: http://www.penglixun.com/tech/database/static_compile_mysql_with_tcmalloc.html Linux malloc function performance problems, most people write C in Linux

The content of this article complies with the CC copyright agreement, can be reproduced at will, but must be in the form of hyperlink to indicate the original source of the article and author information and copyright statement URL: http://www.penglixun.com/tech/database/static_compile_mysql_with_tcmalloc.html

In Linux, the performance of the malloc function may be poor. Most people who write C in Linux may feel deeply and use the memory pool to improve the memory allocation efficiency.
Google's open-source tcmalloc improves the efficiency of malloc. in a large number of malloc and free operations, the memory curve of the operating system is significantly smoother than that of the malloc function in Linux. In the case of high concurrency, improve program stability and performance.
Generally, the tcmalloc dynamic library is added to mysqld_safe on the Internet for startup. However, MySQL is statically compiled. Does dynamic loading take effect at this time? Therefore, it is better to statically compile MySQL.

To compile tcmalloc, you must first compile libunwind:

Wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99.tar.gz
Tar zxvf libunwind-0.99.tar.gz

CHOST = x86_64-pc-linux-gnu "\
CFLAGS = "-O3-fPIC \
-Fomit-frame-pointer \
-Pipe \
-March = nocona \
-Mfpmath = sse \
M128bit-long-double \
-Mmmx \
-Msse \
-Msse2 \
-Maccumulate-outgoing-args \
-M64 \
-Ftree-loop-linear \
-Fprefetch-loop-arrays \
-Freg-struct-return \
-Fgcse-sm \
-Fgcse-las \
-Frename-registers \
-Fforce-addr \
-Fivopts \
-Ftree-vectorize \
-Ftracer \
-Frename-registers \
-Minline-all-stringops \
-Fbranch-target-load-optimize2 ″\
CXXFLAGS = "$ {CFLAGS }"\
./Configure & make install

Then compile tcmalloc:

Tar zxvf google-perftools-1.6.tar.gz

CHOST = x86_64-pc-linux-gnu "\
CFLAGS = "-O3 \
-Fomit-frame-pointer \
-Pipe \
-March = nocona \
-Mfpmath = sse \
M128bit-long-double \
-Mmmx \
-Msse \
-Msse2 \
-Maccumulate-outgoing-args \
-M64 \
-Ftree-loop-linear \
-Fprefetch-loop-arrays \
-Freg-struct-return \
-Fgcse-sm \
-Fgcse-las \
-Frename-registers \
-Fforce-addr \
-Fivopts \
-Ftree-vectorize \
-Ftracer \
-Frename-registers \
-Minline-all-stringops \
-Fbranch-target-load-optimize2 ″\
CXXFLAGS = "$ {CFLAGS }"\
./Configure & make install

Remember to add libtammloc to the system path; otherwise, MySQL compilation cannot be found:

Echo "/usr/local/lib">/etc/ld. so. conf. d/usr_local_lib.conf
/Sbin/ldconfig

Finally, we compiled MySQL:

CXX = gcc \
CHOST = x86_64-pc-linux-gnu "\
CFLAGS = "-O3 \
-Fomit-frame-pointer \
-Pipe \
-March = nocona \
-Mfpmath = sse \
M128bit-long-double \
-Mmmx \
-Msse \
-Msse2 \
-Maccumulate-outgoing-args \
-M64 \
-Ftree-loop-linear \
-Fprefetch-loop-arrays \
-Freg-struct-return \
-Fgcse-sm \
-Fgcse-las \
-Frename-registers \
-Fforce-addr \
-Fivopts \
-Ftree-vectorize \
-Ftracer \
-Frename-registers \
-Minline-all-stringops \
-Felide-constructors \
-Fno-exceptions \
-Fno-rtti \
-Fbranch-target-load-optimize2 ″\
CXXFLAGS = "$ {CFLAGS }"\
./Configure-prefix =/usr/alibaba/install/mysql-ent-custom-5.1.49sp1 \
-With-server-suffix =-alibaba-edition \
-With-mysqld-user = mysql \
-With-plugins = partition, blackhole, csv, heap, innobase, myisam, myisammrg \
-With-charset = utf8 \
-With-collation = utf8_general_ci \
-With-extra-charsets = gbk, gb2312, utf8, ascii \
-With-big-tables \
-With-fast-mutexes \
-With-zlib-dir = bundled \
-Enable-Cycler \
-Enable-profiling \
-Enable-local-infile \
-Enable-thread-safe-client \
-With-readline \
-With-pthread \
-With-embedded-server \
-With-client-ldflags =-all-static \
-With-mysqld-ldflags =-all-static \
-With-mysqld-ldflags =-ltcmalloc \
-Without-query-cache \
-Without-geometry \
-Without-debug \
-Without-ndb-debug
Make & make install

After trial, the memory allocation and release curves in high concurrency scenarios are more stable than those in Linux native.

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.