jemalloc originated from Jason Evans's paper on BSDcan conference in 2006: "A Scalable Concurrent malloc Implementation for FreeBSD". Jason believes that phkmalloc (FreeBSD's previous malloc implementation by Kamp (1998)) does not consider the case of multiprocessors, so it has poor performance under multithreaded concurrency (this is true), while jemalloc is suitable for memory allocation management under multithreaded. Since 2007, it has been introduced under the FreeBSD standard. Many software technology innovations are initiated by FreeBSD. Technology that is widely used in FreeBSD will be slowly imported into Linux.
After Redis 2.4, jemalloc is used by default for memory management; tengine also integrates jemalloc. From the results of evaluations by various parties, jemalloc shows that it is not comparable to Google tcmalloc, and both are at the highest level in the memory manager field. As shown in the figure below:
The leftmost is glibc's malloc, and the rightmost is jemalloc. As can be seen from the chart, jemalloc's performance is more than twice that of glibc. Very overwhelming performance differences. Therefore, applications that use jemalloc will naturally be much faster. Next to Jemalloc is tcmalloc. Tcmalloc's performance is very different from it, with jemalloc2.1.0 being 4.5% slower. The 1.4 version of tcmalloc on the figure has now reached version 2.1, so in fact, the two should be incomparable. Jemalloc founder Jason Evans also realized this, saying that jemalloc is more efficient on computers above CPU core 8.
MySQL performance test-jemalloc memory management: http://www.linuxeye.com/Linux/1914.html
jemalloc has been added to the "lnmp latest source code one-click installation package" as an option
Install jemalloc
cd lnmp/srcwget http://www.canonware.com/download/jemalloc/jemalloc-3.4.0.tar.bz2tar xjf jemalloc-3.4.0.tar.bz2cd jemalloc-3.4.0./configuremake && make installecho '/usr/local/lib' > /etc/ld.so.conf.d/local.confldconfig
Optimize MySQL with jemalloc
Method 1:
MySQL/MaridDB 5.5 compilation method, add the following parameters when cmake precompilation
-DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" -DWITH_SAFEMALLOC=OFF
Method 2:
Directly load and modify mysqld_safe
Find file /usr/local/mysql/bin/mysqld_safe
Add under #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_safeservice mysqld restart
Optimize Nginx with jemalloc
Add the following parameters when compiling NGINX:
--with-ld-opt="-ljemalloc"
Specific implementation:
cd lnmp/src/nginx-1.4.2make 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 jemalloc optimization Nginx is effective, as follows
lsof -n | grep jemalloc