这两天刚好做PHP-FPM的内存优化,在查看PHP-FPM内存使用情况时发现locale-archive占用内存96M,该文件为语言,环境,字体相关的索引文件,由于很多语言无用,所以删除以压榨内存,凡setlocale的程序都会将locale-archive文件mmap到内存当中
内存使用细节
[root@AY14070313210045657aZ ~]# pmap -d `pidof php-fpm|awk '{print $1}'`
7124: php-fpm: pool www
Address Kbytes Mode Offset Device Mapping
0000000000400000 11028 r-x-- 0000000000000000 0ca:00001 php-fpm
00000000010c5000 116 rw--- 0000000000ac5000 0ca:00001 php-fpm
....省略
00007f033ea1a000 64 r-x-- 0000000000000000 0ca:00001 libGB.so
00007f033ea2a000 2044 ----- 0000000000010000 0ca:00001 libGB.so
00007f033ec29000 4 r---- 000000000000f000 0ca:00001 libGB.so
00007f033ec2a000 4 rw--- 0000000000010000 0ca:00001 libGB.so
00007f033ec2b000 12 r-x-- 0000000000000000 0ca:00001 EUC-CN.so
00007f033ec2e000 2044 ----- 0000000000003000 0ca:00001 EUC-CN.so
00007f033ee2d000 4 r---- 0000000000002000 0ca:00001 EUC-CN.so
00007f033ee2e000 4 rw--- 0000000000003000 0ca:00001 EUC-CN.so
00007f033ee2f000 96832 r---- 0000000000000000 0ca:00001 locale-archive
00007f0344cbf000 48 r-x-- 0000000000000000 0ca:00001 libnss_files-2.12.so
00007f0344ccb000 2048 ----- 000000000000c000 0ca:00001 libnss_files-2.12.so
00007f0344ecb000 4 r---- 000000000000c000 0ca:00001 libnss_files-2.12.so
00007f0344ecc000 4 rw--- 000000000000d000 0ca:00001 libnss_files-2.12.so
00007f0344ecd000 28 r-x-- 0000000000000000 0ca:00001 pdo_mysql.so
00007f0344ed4000 2044 ----- 0000000000007000 0ca:00001 pdo_mysql.so
00007f03450d3000 4 rw--- 0000000000006000 0ca:00001 pdo_mysql.so
进行相应调整(此处请酌情考虑应用需要的)
###重命名该文件###
[root@ipython ~]# mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.bak
###重新添加语言支持###
[root@ipython ~]# localedef -i en_US -f UTF-8 en_US.UTF-8
[root@ipython ~]# localedef -i zh_CN -f UTF-8 zh_CN.UTF-8
###可选中文支持###
[root@ipython ~]# localedef -i zh_CN -f GB2312 zh_CN
[root@ipython ~]# localedef -i zh_CN -f GB2312 zh_CN.GB2312
[root@ipython ~]# localedef -i zh_CN -f GBK zh_CN.GBK
###富中文支持(HK/TW/SG)####
[root@ipython ~]# localedef -f UTF-8 -i zh_HK zh_HK.UTF-8
[root@ipython ~]# localedef -f UTF-8 -i zh_TW zh_TW.UTF-8
[root@ipython ~]# localedef -f UTF-8 -i zh_SG zh_SG.UTF-8
####重启服务器,再查看使用情况####
[root@ipython ~]# pmap -d `pidof php-fpm|awk '{print $1}'`|awk '/locale/'
00007f38d0717000 3104 r---- 0000000000000000 0ca:00001 locale-archive
###这样下来就小了不少了,如果需要保险点的方法可以使用以下命令###
[root@ipython ~]# localedef --list-archive |egrep -v ^"en_US|zh" |xargs localedef --delete-from-archive
[root@ipython ~]# mv -f /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.bak
[root@ipython ~]# build-locale-archive
(责任编辑:IT) |