Nginx和php性能优化相关

一直以来都是在写Hadoop,很少写nginx和php相关的东西了。网上绝大多数文章是优化linux系统参数,优化nginx,php的配置参数等等,尝试写个不同视角的,跟具体技术点关系太大的,主要是思路。

从编译安装nginx和php开始捋一下。

编译nginx和php一个最基本的原则是,尽可能编译更少的附加模块,nginx和php或者更早的apache,为了完成某项特定的功能,会将该功能已动态连接库的形式包含在软件里面,在linux下面是.so后缀的文件。一般来说,用户在configure阶段,可以自己选择--with-xxx或者--without-xxx来决定是否使用它提供的模块。为了方便,我们当然可以这样做,比如我们要在php里面使用curl的函数,就指定--with-curl=/usr/local/curl这种方式去configure。但是,除非这个模块是你必须使用的,否则就不要指定编译它。

原则一:如果不需要这个模块,就不要编译它。

原因是这样,当你启动nginx或者php进程的时候,这些进程都会打开所有你所编译的这些动态连接库,每个动态链接库都会占用linux系统的FD资源,这个用lsof是可以很清楚的看到的。同样,你的log文件也是会占用FD资源。

[root@collect-crash5-197 Hload]# lsof | grep nginx

nginx 14214 nobody cwd DIR 8,9 4096 31623598 /opt/modules/tengine/sbin

nginx 14214 nobody rtd DIR 8,2 4096 2 /

nginx 14214 nobody txt REG 8,9 3114093 31623599 /opt/modules/tengine/sbin/nginx

nginx 14214 nobody mem REG 8,2 143600 65301 /lib64/ld-2.5.so

nginx 14214 nobody mem REG 8,2 1722304 65305 /lib64/libc-2.5.so

nginx 14214 nobody mem REG 8,2 129984 65356 /lib64/libpcre.so.0.0.1

nginx 14214 nobody mem REG 8,2 145824 65350 /lib64/libpthread-2.5.so

nginx 14214 nobody mem REG 8,2 18152 65349 /lib64/libutil-2.5.so

nginx 14214 nobody mem REG 8,2 615136 65315 /lib64/libm-2.5.so

nginx 14214 nobody mem REG 8,2 85544 65591 /lib64/libz.so.1.2.3

nginx 14214 nobody mem REG 8,2 48600 65346 /lib64/libcrypt-2.5.so

nginx 14214 nobody mem REG 8,2 92736 65327 /lib64/libresolv-2.5.so

nginx 14214 nobody mem REG 8,3 1262416 4146256 /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so

nginx 14214 nobody mem REG 8,2 114352 65623 /lib64/libnsl-2.5.so

nginx 14214 nobody mem REG 8,2 23360 65329 /lib64/libdl-2.5.so

nginx 14214 nobody mem REG 8,3 120945 4245561 /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/nginx/nginx.so

nginx 14214 nobody DEL REG 0,9 1301143625 /dev/zero

nginx 14214 nobody mem REG 8,2 53880 65306 /lib64/libnss_files-2.5.so

nginx 14214 nobody 0u CHR 1,3 1670 /dev/null

nginx 14214 nobody 1u CHR 1,3 1670 /dev/null

nginx 14214 nobody 2w REG 8,9 19614456983 31719533 /opt/modules/tengine/logs/error.log

nginx 14214 nobody 3w REG 8,17 0 73587637 /data/logs/error5/access.log

nginx 14214 nobody 5u unix 0xffff81010f64ec40 1596291379 socket

nginx 14214 nobody 7u unix 0xffff810186199480 1596291382 socket

nginx 14214 nobody 9u unix 0xffff81010886eec0 1596291384 socket

nginx 14214 nobody 10u IPv4 1301143624 TCP *:http (LISTEN)

nginx 14214 nobody 11w REG 8,17 0 90475700 /data/logs/errorv/access.log

nginx 14214 nobody 12w REG 8,17 0 1507590 /data/logs/errorcode/access.log

nginx 14214 nobody 13w REG 8,17 0 73662516 /data/logs/mobile/access.log

nginx 14214 nobody 14w REG 8,9 8612894912 31719506 /opt/modules/tengine/logs/access.log

nginx 14214 nobody 15w REG 8,9 19614456983 31719533 /opt/modules/tengine/logs/error.log

nginx 14214 nobody 16u unix 0xffff81010886fc80 1596291389 socket

nginx 14214 nobody 17u unix 0xffff8101185cda00 1596291378 socket

nginx 14214 nobody 18r 0000 0,11 0 1596291381 eventpoll

nginx 14214 nobody 19u 0000 0,7 0 356 anon_inode

nginx 14214 nobody 20u unix 0xffff81010886f440 1596291391 socket

nginx 14214 nobody 21u unix 0xffff81011b1d3a00 1596291393 socket

nginx 14214 nobody 23u unix 0xffff81013d2c5d00 1596291396 socket

nginx 14214 nobody 25u unix 0xffff81013d2c5780 1596291398 socket

nginx 14214 nobody 27u unix 0xffff81013d2c5200 1596291402 socket

nginx 14214 nobody 29u unix 0xffff81013d2c4c80 1596291404 socket

nginx 14214 nobody 31u unix 0xffff81013d2c4700 1596291406 socket

nginx 14214 nobody 33u unix 0xffff81013d2c4180 1596291408 socket

nginx 14214 nobody 35u unix 0xffff8102020a3940 1596291410 socket

nginx 14214 nobody 37u unix 0xffff8102020a33c0 1596291412 socket

nginx 14214 nobody 39u unix 0xffff8102020a2e40 1596291415 socket

nginx 14215 nobody cwd DIR 8,9 4096 31623598 /opt/modules/tengine/sbin

nginx 14215 nobody rtd DIR 8,2 4096 2 /

nginx 14215 nobody txt REG 8,9 3114093 31623599 /opt/modules/tengine/sbin/nginx

nginx 14215 nobody mem REG 8,2 143600 65301 /lib64/ld-2.5.so

nginx 14215 nobody mem REG 8,2 1722304 65305 /lib64/libc-2.5.so

nginx 14215 nobody mem REG 8,2 129984 65356 /lib64/libpcre.so.0.0.1

nginx 14215 nobody mem REG 8,2 145824 65350 /lib64/libpthread-2.5.so

nginx 14215 nobody mem REG 8,2 18152 65349 /lib64/libutil-2.5.so

nginx 14215 nobody mem REG 8,2 615136 65315 /lib64/libm-2.5.so

nginx 14215 nobody mem REG 8,2 85544 65591 /lib64/libz.so.1.2.3

nginx 14215 nobody mem REG 8,2 48600 65346 /lib64/libcrypt-2.5.so

nginx 14215 nobody mem REG 8,2 92736 65327 /lib64/libresolv-2.5.so

nginx 14215 nobody mem REG 8,3 1262416 4146256 /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so

nginx 14215 nobody mem REG 8,2 114352 65623 /lib64/libnsl-2.5.so

nginx 14215 nobody mem REG 8,2 23360 65329 /lib64/libdl-2.5.so

nginx 14215 nobody mem REG 8,3 120945 4245561 /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/nginx/nginx.so

nginx 14215 nobody DEL REG 0,9 1301143625 /dev/zero

nginx 14215 nobody mem REG 8,2 53880 65306 /lib64/libnss_files-2.5.so

nginx 14215 nobody 0u CHR 1,3 1670 /dev/null

nginx 14215 nobody 1u CHR 1,3 1670 /dev/null

nginx 14215 nobody 2w REG 8,9 19614456983 31719533 /opt/modules/tengine/logs/error.log

nginx 14215 nobody 3w REG 8,17 0 73587637 /data/logs/error5/access.log

nginx 14215 nobody 5u unix 0xffff810186199480 1596291382 socket

nginx 14215 nobody 7u unix 0xffff81010886eec0 1596291384 socket

nginx 14215 nobody 9u unix 0xffff81010886fc80 1596291389 socket

nginx 14215 nobody 10u IPv4 1301143624 TCP *:http (LISTEN)

nginx 14215 nobody 11w REG 8,17 0 90475700 /data/logs/errorv/access.log

nginx 14215 nobody 12w REG 8,17 0 1507590 /data/logs/errorcode/access.log

nginx 14215 nobody 13w REG 8,17 0 73662516 /data/logs/mobile/access.log

nginx 14215 nobody 14w REG 8,9 8612894912 31719506 /opt/modules/tengine/logs/access.log

nginx 14215 nobody 15w REG 8,9 19614456983 31719533 /opt/modules/tengine/logs/error.log

nginx 14215 nobody 16u unix 0xffff8101185cdcc0 1596291377 socket

nginx 14215 nobody 17u unix 0xffff81010886f440 1596291391 socket

nginx 14215 nobody 18u unix 0xffff81011b1d3a00 1596291393 socket

nginx 14215 nobody 19u unix 0xffff81010886ec00 1596291380 socket

nginx 14215 nobody 20r 0000 0,11 0 1596291386 eventpoll

nginx 14215 nobody 21u 0000 0,7 0 356 anon_inode

nginx 14215 nobody 23u unix 0xffff81013d2c5d00 1596291396 socket

nginx 14215 nobody 25u unix 0xffff81013d2c5780 1596291398 socket

nginx 14215 nobody 27u unix 0xffff81013d2c5200 1596291402 socket

nginx 14215 nobody 29u unix 0xffff81013d2c4c80 1596291404 socket

nginx 14215 nobody 31u unix 0xffff81013d2c4700 1596291406 socket

nginx 14215 nobody 33u unix 0xffff81013d2c4180 1596291408 socket

nginx 14215 nobody 35u unix 0xffff8102020a3940 1596291410 socket

nginx 14215 nobody 37u unix 0xffff8102020a33c0 1596291412 socket

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/5e3a803626a955cde365a63b67edae00.html