Lamp优化实践

5,137 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,137
On SlideShare
0
From Embeds
0
Number of Embeds
3,725
Actions
Shares
0
Downloads
16
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Lamp优化实践

  1. 1. LAMP 优化过程 周灵杰 http://blog.netzhou.net
  2. 2. 高性能 非代码层面 对系统的设计 对开源软件方案的选择 对系统的监控 对服务器设置,优化
  3. 3. 架 构设计原则 易于扩展 结构简单 采用成熟的开源软件及解决方案 层次清晰 先可用,抗住,再优化 过度设计比不设计更龌龊
  4. 4. 现代硬件架构 CPU 转向多核,非提高 CPU 的主频 内存是新的磁盘,大内存多核 NUMA 磁盘,提高容量,非转速, IOPS 不高 新型 SSD , PCI-E 型 SSD ,混合存储 网卡的多通道, 10G
  5. 5. Web Server Nginx + php-fpm Nginx + php-cgi Apache + mod_php Apache + php-cgi …
  6. 6. Nginx Tips worker_processes worker_cpu_affinity open_file_cache max=xx inactive=xxs; open_file_cache_valid xxs; open_file_cache_min_uses 2; sendfile on; keepalive_timeout xx; tcp_nopush on; tcp_nodelay on;
  7. 7. PHP-fpm Tips <value name="listen_address">/dev/shm/php.socket</value> <value name="max_children">512</value> <value name="request_slowlog_timeout">1s</value> <value name="slowlog">logs/slow.log</value> <value name="rlimit_files">65535</value>
  8. 8. DB Cache Redis Memcached
  9. 9. MySQL MySQL Server tunning 分库,分表 索引 &Explain 主从同步,读写分离 Query Cache FlashCache 混合存储
  10. 10. OS EXT4 , XFS 文件系统 CPU IO 调度算法 IO 队列长度 Raid 卡 Cache 策略,电池放电对于磁盘 IO 的影 响 多核大内存 NUMA 网卡软中断多核( RPS , RFS , RSS ) Iptables 调整 Ulimit
  11. 11. TCP net.ipv4.tcp_max_syn_backlog = 65536 net.core.netdev_max_backlog = 32768 net.core.somaxconn = 32768 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_congestion_control = bic net.ipv4.tcp_ecn = 0 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_keepalive_intvl = 15 net.ipv4.tcp_keepalive_probes = 3 net.ipv4.tcp_keepalive_time = 60 net.ipv4.tcp_fin_timeout = 30 net.ipv4.ip_local_port_range = 1024 65535
  12. 12. 无处 不在的 cache Browser cache Page cache PHP 的 Realpath Cache Nginx 的 facgi-cache PHP opcode ( APC,eAccelerator,XCache ) DB Cache
  13. 13. 监控 Nagios Cacti PHP Slow function PHP Error Log Nginx Error Log Mysql Slow Log Redis Slow log
  14. 14. 其它 PHP extension GD < Imagemagic < Graphicsmagick memcached < memcache xCache < eAccelerator < APCPHP Profile xdebug, xhprofhiphop-php…
  15. 15. Q&A

×