Jemalloc optimize MySQL and Nginx_java

Source: Internet
Author: User

Jemalloc from Jason Evans's paper published in Bsdcan conference in 2006: "A Scalable Concurrent malloc for implementation". Jason believes that Phkmalloc (FreeBSD's previous malloc implementation by Kamp (1998)) does not consider multiprocessor situations, so low performance in multithreaded concurrency (as is the case), and Jemalloc is suitable for multithreading under the memory allocation management. It has been introduced with the FreeBSD standard since 2007. Many of the software innovations are FreeBSD initiated, and a wide range of technologies in FreeBSD will slowly be imported into Linux.

Redis version 2.4, the default is to use Jemalloc to do memory management; Tengine also integrates Jemalloc. Jemalloc from the results of the review can be seen with Google Tcmalloc are not the same as the memory manager in the field of the highest level. The following figure:

The leftmost is GLIBC's malloc, and the far right is jemalloc. As can be seen from the chart, the performance of Jemalloc is more than twice times glibc. Very overwhelming performance difference. As a result, applications that use Jemalloc will naturally be much faster. Next to Jemalloc is Tcmalloc. The performance of Tcmalloc is very small, low jemalloc2.1.0 is 4.5% slow. The 1.4 version of the picture and the Tcmalloc, and now to the 2.1 version, so in fact the two should not be the same. Jemalloc's founder, Jason Evans, is also aware of this, saying that Jemalloc is more efficient on computers with a CPU core of more than 8.

MySQL performance test--jemalloc memory management: http://www.linuxeye.com/Linux/1914.html

Jemalloc has been added as an option to the "LNMP latest source code one-button installation package"

Install Jemalloc

CD lnmp/src
wget http://www.canonware.com/download/jemalloc/jemalloc-3.4.0.tar.bz2
tar xjf jemalloc-3.4.0.tar.bz2
cd jemalloc-3.4.0
./configure make
&& make install
echo '/usr/local/ Lib ' >/etc/ld.so.conf.d/local.conf
ldconfig

Using Jemalloc to optimize MySQL

Method One:

MYSQL/MARIDDB 5.5 compilation method, cmake with the following parameters during precompilation

-dcmake_exe_linker_flags= "-ljemalloc"-dwith_safemalloc=off

Method Two:

Direct Load Modification Mysqld_safe
Find Files/usr/local/mysql/bin/mysqld_safe
Add under the #executing Mysqld_safe
Ld_preload=/usr/local/lib/libjemalloc.so

Restart MySQL
Use the following code to automatically modify the Mysqld_safe file

Sed-i ' s@executing mysqld_safe@executing mysqld_safe\nexport ld_preload=/usr/local/lib/libjemalloc.so@ '/usr/local/ Mysql/bin/mysqld_safe
Service mysqld Restart

Using Jemalloc to optimize Nginx

Add the following parameters when compiling Nginx:

--with-ld-opt= "-ljemalloc"

Specific implementation:

CD lnmp/src/nginx-1.4.2 make clean
./configure--prefix=/usr/local/nginx--user=www--group=www
With-http_stub_status_module--with-http_ssl_module--with-http_flv_module \
--with-http_gzip_static_module-- with-ld-opt= "-ljemalloc" make
&& make install

Verify that the Jemalloc optimization nginx is in effect, as follows

Lsof-n | grep jemalloc

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.