jemalloc优化MySQL、Tengine/nginx内存管理

 安装jemalloc

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

使用jemalloc优化MySQL
MySQL/MaridDB 5.5编译方法,cmake预编译时加上下面参数

-DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" -DWITH_SAFEMALLOC=OFF

或者直接加载,修改mysqld_safe

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

使用jemalloc优化Tenginx

cd tengine-2.0.3/
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-jemalloc
make
&& make install

使用jemalloc优化nginx

cd 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

 验证jemalloc是否生效,如下

lsof -n | grep jemalloc

如果你以前安装过tengine或者nginx,此时要进行平滑升级

首先,先向nginx程序发送一个USR2的信号

kill -USR2 `cat /usr/local/webserver/nginx/nginx.pid`
运行完该步后,会发现此时的nginx.pid文件会变成nginx.pid.oldbin 。而通过ps 查看时,会发现有两个nginx master主进程。一个是刚刚启动的。接下来让老的nginx 从容而有颜面的退役:

kill -QUIT `cat /App/nginx/logs/nginx.pid.oldbin`
总结来说:上面两个操作就是:让nginx 重新用目前的sbin目录下的nginx再运行,同时保持旧的存在。接着向旧版本的nginx发送一个quit信号,使其不再接受新的请求(新的请求由新的nginx处理),同时对未完成的请求,完成后退出。

Nginx 的信号控制

TERM, INT 快速关闭
QUIT 从容关闭
HUP 平滑重启,重新加载配置文件
USR1 重新打开日志文件,在切割日志时用途较大
USR2 平滑升级可执行程序
WINCH 从容关闭工作进程

300*300
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00506 秒