gperftools安装使用

您所在的位置:网站首页 gperftools安装 gperftools安装使用

gperftools安装使用

2023-07-01 12:21| 来源: 网络整理| 查看: 265

96ec3782b3cd1aaa8e8783ca0988cc6c.png 一、前言

1、使用google开发的google-perftools优化nginx的内存分配效率和速度,帮助在高并发的情况下控制内存的使用。

2、TCMalloc在内存的分配上效率和速度要比malloc高得多。但是nginx的内存占用其实是很少的,一个进程占用的内存大概只有12M左右,所有google-perftools对nginx的优化效果可能不太明显。

二、安装

1、下载并安装google-perftools

# 从github上下载perftools工具包shell> wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz# 注意:# 1、如果是32位系统,在configure gperftools的时候,可以不添加--enable-frame-pointers参数。# 2、如果是64位系统,需要先安装libunwind,再在configure gperftools的时候,添加--enable-frame-pointers参数。shell> yum install epel-release -yshell> yum install libunwind-devel -yshell> tar zxvf gperftools-2.7.tar.gzshell> cd gperftools-2.7shell> ./configure --enable-frame-pointers --enable-libunwind --with-tcmalloc-pagesize=32shell> make && make install

2、使nginx支持google-perftools

# 重新编译ngx,添加--with-google_perftools_module# 简单演示参数添加方法,详细的nginx安装过程,请参考《源码安装openresty》shell> ./configure --with-google_perftools_moduleshell> make && make install

3、配置nginx对google-perftools的支持

# 添加线程目录shell> mkdir /tmp/tcmallocshell> chmod 0777 /tmp/tcmalloc# 修改nginx.conf,在pid行下面添加如下信息google_perftools_profiles /tmp/tcmalloc;# 重启nginxshell> /opt/openresty/nginx/sbin/nginx -s reload# 验证是否支持shell> lsof -n |grep tcmallocnginx 1414 nobody 12w REG 252,1 0 1452011 /tmp/tcmalloc.1414nginx 1415 nobody 14w REG 252,1 0 1452010 /tmp/tcmalloc.1415# 备注:tcmalloc的记录文件数量与nginx.conf中worker_processes的值有关,每个worker对应一个tcmalloc文件。

4、可能会遇到的问题

# 启动nginx,发现缺少libprofiler.so.0动态库的支持shell> /opt/openresty/nginx/sbin/nginx /opt/openresty/nginx/sbin/nginx: error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory# 查找系统下是否有libprofiler.so.0动态库shell> whereis libprofiler.so.0libprofiler.so: /usr/local/lib/libprofiler.so.0 /usr/local/lib/libprofiler.so# 由于不在nginx程序查找的目录下,所以需要创建软链接# 评估缺少的动态库支持,可通过ldd /opt/openresty/nginx/sbin/nginx的方式,查看"not found"部分。shell> ln -s /usr/local/lib/libprofiler.so.0.4.18 /lib64/libprofiler.so.0

至此,nginx下的google-perftools优化安装完成。

作者:龍龍小宝

原文:https://www.cnblogs.com/91donkey/p/11513175.html



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3