手机版
你好,游客 登录 注册
背景:
阅读新闻

Nginx和php性能优化相关

[日期:2013-04-18] 来源:51cto  作者:Slaytanic [字体:大 中 小]

一直以来都是在写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资源。

  1. [root@collect-crash5-197 Hload]# lsof | grep nginx
  2. nginx 14214 nobody cwd DIR 8,9 4096 31623598 /opt/modules/tengine/sbin
  3. nginx 14214 nobody rtd DIR 8,2 4096 2 /
  4. nginx 14214 nobody txt REG 8,9 3114093 31623599 /opt/modules/tengine/sbin/nginx
  5. nginx 14214 nobody mem REG 8,2 143600 65301 /lib64/ld-2.5.so
  6. nginx 14214 nobody mem REG 8,2 1722304 65305 /lib64/libc-2.5.so
  7. nginx 14214 nobody mem REG 8,2 129984 65356 /lib64/libpcre.so.0.0.1
  8. nginx 14214 nobody mem REG 8,2 145824 65350 /lib64/libpthread-2.5.so
  9. nginx 14214 nobody mem REG 8,2 18152 65349 /lib64/libutil-2.5.so
  10. nginx 14214 nobody mem REG 8,2 615136 65315 /lib64/libm-2.5.so
  11. nginx 14214 nobody mem REG 8,2 85544 65591 /lib64/libz.so.1.2.3
  12. nginx 14214 nobody mem REG 8,2 48600 65346 /lib64/libcrypt-2.5.so
  13. nginx 14214 nobody mem REG 8,2 92736 65327 /lib64/libresolv-2.5.so
  14. nginx 14214 nobody mem REG 8,3 1262416 4146256 /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so
  15. nginx 14214 nobody mem REG 8,2 114352 65623 /lib64/libnsl-2.5.so
  16. nginx 14214 nobody mem REG 8,2 23360 65329 /lib64/libdl-2.5.so
  17. 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
  18. nginx 14214 nobody DEL REG 0,9 1301143625 /dev/zero
  19. nginx 14214 nobody mem REG 8,2 53880 65306 /lib64/libnss_files-2.5.so
  20. nginx 14214 nobody 0u CHR 1,3 1670 /dev/null
  21. nginx 14214 nobody 1u CHR 1,3 1670 /dev/null
  22. nginx 14214 nobody 2w REG 8,9 19614456983 31719533 /opt/modules/tengine/logs/error.log
  23. nginx 14214 nobody 3w REG 8,17 0 73587637 /data/logs/error5/access.log
  24. nginx 14214 nobody 5u unix 0xffff81010f64ec40 1596291379 socket
  25. nginx 14214 nobody 7u unix 0xffff810186199480 1596291382 socket
  26. nginx 14214 nobody 9u unix 0xffff81010886eec0 1596291384 socket
  27. nginx 14214 nobody 10u IPv4 1301143624 TCP *:http (LISTEN)
  28. nginx 14214 nobody 11w REG 8,17 0 90475700 /data/logs/errorv/access.log
  29. nginx 14214 nobody 12w REG 8,17 0 1507590 /data/logs/errorcode/access.log
  30. nginx 14214 nobody 13w REG 8,17 0 73662516 /data/logs/mobile/access.log
  31. nginx 14214 nobody 14w REG 8,9 8612894912 31719506 /opt/modules/tengine/logs/access.log
  32. nginx 14214 nobody 15w REG 8,9 19614456983 31719533 /opt/modules/tengine/logs/error.log
  33. nginx 14214 nobody 16u unix 0xffff81010886fc80 1596291389 socket
  34. nginx 14214 nobody 17u unix 0xffff8101185cda00 1596291378 socket
  35. nginx 14214 nobody 18r 0000 0,11 0 1596291381 eventpoll
  36. nginx 14214 nobody 19u 0000 0,7 0 356 anon_inode
  37. nginx 14214 nobody 20u unix 0xffff81010886f440 1596291391 socket
  38. nginx 14214 nobody 21u unix 0xffff81011b1d3a00 1596291393 socket
  39. nginx 14214 nobody 23u unix 0xffff81013d2c5d00 1596291396 socket
  40. nginx 14214 nobody 25u unix 0xffff81013d2c5780 1596291398 socket
  41. nginx 14214 nobody 27u unix 0xffff81013d2c5200 1596291402 socket
  42. nginx 14214 nobody 29u unix 0xffff81013d2c4c80 1596291404 socket
  43. nginx 14214 nobody 31u unix 0xffff81013d2c4700 1596291406 socket
  44. nginx 14214 nobody 33u unix 0xffff81013d2c4180 1596291408 socket
  45. nginx 14214 nobody 35u unix 0xffff8102020a3940 1596291410 socket
  46. nginx 14214 nobody 37u unix 0xffff8102020a33c0 1596291412 socket
  47. nginx 14214 nobody 39u unix 0xffff8102020a2e40 1596291415 socket
  48. nginx 14215 nobody cwd DIR 8,9 4096 31623598 /opt/modules/tengine/sbin
  49. nginx 14215 nobody rtd DIR 8,2 4096 2 /
  50. nginx 14215 nobody txt REG 8,9 3114093 31623599 /opt/modules/tengine/sbin/nginx
  51. nginx 14215 nobody mem REG 8,2 143600 65301 /lib64/ld-2.5.so
  52. nginx 14215 nobody mem REG 8,2 1722304 65305 /lib64/libc-2.5.so
  53. nginx 14215 nobody mem REG 8,2 129984 65356 /lib64/libpcre.so.0.0.1
  54. nginx 14215 nobody mem REG 8,2 145824 65350 /lib64/libpthread-2.5.so
  55. nginx 14215 nobody mem REG 8,2 18152 65349 /lib64/libutil-2.5.so
  56. nginx 14215 nobody mem REG 8,2 615136 65315 /lib64/libm-2.5.so
  57. nginx 14215 nobody mem REG 8,2 85544 65591 /lib64/libz.so.1.2.3
  58. nginx 14215 nobody mem REG 8,2 48600 65346 /lib64/libcrypt-2.5.so
  59. nginx 14215 nobody mem REG 8,2 92736 65327 /lib64/libresolv-2.5.so
  60. nginx 14215 nobody mem REG 8,3 1262416 4146256 /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so
  61. nginx 14215 nobody mem REG 8,2 114352 65623 /lib64/libnsl-2.5.so
  62. nginx 14215 nobody mem REG 8,2 23360 65329 /lib64/libdl-2.5.so
  63. 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
  64. nginx 14215 nobody DEL REG 0,9 1301143625 /dev/zero
  65. nginx 14215 nobody mem REG 8,2 53880 65306 /lib64/libnss_files-2.5.so
  66. nginx 14215 nobody 0u CHR 1,3 1670 /dev/null
  67. nginx 14215 nobody 1u CHR 1,3 1670 /dev/null
  68. nginx 14215 nobody 2w REG 8,9 19614456983 31719533 /opt/modules/tengine/logs/error.log
  69. nginx 14215 nobody 3w REG 8,17 0 73587637 /data/logs/error5/access.log
  70. nginx 14215 nobody 5u unix 0xffff810186199480 1596291382 socket
  71. nginx 14215 nobody 7u unix 0xffff81010886eec0 1596291384 socket
  72. nginx 14215 nobody 9u unix 0xffff81010886fc80 1596291389 socket
  73. nginx 14215 nobody 10u IPv4 1301143624 TCP *:http (LISTEN)
  74. nginx 14215 nobody 11w REG 8,17 0 90475700 /data/logs/errorv/access.log
  75. nginx 14215 nobody 12w REG 8,17 0 1507590 /data/logs/errorcode/access.log
  76. nginx 14215 nobody 13w REG 8,17 0 73662516 /data/logs/mobile/access.log
  77. nginx 14215 nobody 14w REG 8,9 8612894912 31719506 /opt/modules/tengine/logs/access.log
  78. nginx 14215 nobody 15w REG 8,9 19614456983 31719533 /opt/modules/tengine/logs/error.log
  79. nginx 14215 nobody 16u unix 0xffff8101185cdcc0 1596291377 socket
  80. nginx 14215 nobody 17u unix 0xffff81010886f440 1596291391 socket
  81. nginx 14215 nobody 18u unix 0xffff81011b1d3a00 1596291393 socket
  82. nginx 14215 nobody 19u unix 0xffff81010886ec00 1596291380 socket
  83. nginx 14215 nobody 20r 0000 0,11 0 1596291386 eventpoll
  84. nginx 14215 nobody 21u 0000 0,7 0 356 anon_inode
  85. nginx 14215 nobody 23u unix 0xffff81013d2c5d00 1596291396 socket
  86. nginx 14215 nobody 25u unix 0xffff81013d2c5780 1596291398 socket
  87. nginx 14215 nobody 27u unix 0xffff81013d2c5200 1596291402 socket
  88. nginx 14215 nobody 29u unix 0xffff81013d2c4c80 1596291404 socket
  89. nginx 14215 nobody 31u unix 0xffff81013d2c4700 1596291406 socket
  90. nginx 14215 nobody 33u unix 0xffff81013d2c4180 1596291408 socket
  91. nginx 14215 nobody 35u unix 0xffff8102020a3940 1596291410 socket
  92. nginx 14215 nobody 37u unix 0xffff8102020a33c0 1596291412 socket
  93. nginx 14215 nobody 39u unix 0xffff8102020a2e40 1596291415 socket
linux
相关资讯       Nginx优化  Nginx php优化 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款