Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

4Developers 2015: Scaling LAMP doesn't have to suck - Sebastian Grodzicki

317 views

Published on

Sebastian Grodzicki

Language: Polish

Tradycyjny LAMP sprawdza się świetnie … w środowisku deweloperskim. Nawet jeżeli nie tworzysz kolejnego Facebooka, to każda niedostępność Twojego serwisu kosztuje Cię sporo nerwów oraz pieniędzy. Awaria wystąpi wcześniej lub później. Pytanie nie brzmi "czy" leczy "kiedy". Dlatego warto o tym pomyśleć zawczasu i zbudować taką architekturę, która nie jest podatna na niedostępność z powodu awarii jednego z jej elementów. Jakie narzędzia wybrać? Jak wycisnąć z nich ostatnie soki?

Published in: Software
  • Be the first to comment

4Developers 2015: Scaling LAMP doesn't have to suck - Sebastian Grodzicki

  1. 1. Scaling LAMP doesn't have to suck
  2. 2. Sebastian
 Grodzicki CTO @ GoldenLine ~100 req/s ~4.7M UU
  3. 3. #DevOps
  4. 4. LAMP • Linux • Apache • MySQL • PHP
  5. 5. Scaling LAMP • shared hosting • VPS • dedicated server
  6. 6. Scaling LAMP • split LAMP into LM + LAP • use virtual machines or Docker • forget 127.0.0.1 (AKA localhost) • forget about local storage
  7. 7. A better LAMP • Linux (tuned) • Apache Nginx • MySQL Percona Server • PHP PHP-FPM • Redis • Resque
  8. 8. Linux (tuned) • Linux is mostly sane • use latest kernel • distribution doesn’t matter • (I like Debian)
  9. 9. Tune Linux • open_files • network/sysctl • i/o scheduler
  10. 10. Linux: open_files • default: 1024 (ulimit -n) • soft nofile 999999 • hard nofile 999999
  11. 11. Linux: sysctl • net.ipv4.ip_local_port_range = 1024 65535 • net.ipv4.tcp_tw_recycle = 1 • net.ipv4.tcp_tw_reuse = 1 • net.core.somaxconn = 999999 (default: 128)
  12. 12. Linux: i/o scheduler • $ cat /sys/block/sda/queue/scheduler
 noop deadline [cfq] • $ echo deadline > /sys/block/sda/queue/scheduler • $ cat /sys/block/sda/queue/scheduler
 noop [deadline] cfq
  13. 13. Nginx • open-source HTTP server • swap out Apache • easy + sane config
  14. 14. Nginx 21k req/s @ 10% CPU & 160 MB RAM
  15. 15. Nginx • load balancer • reverse proxy • content caching • streaming media • web server
  16. 16. Percona Server • open source MySQL fork • patches from Twitter and Google • drop-in MySQL replacement • faster at scale, more reliable
  17. 17. MySQL vs Percona new transactions per minute
  18. 18. Percona Server • only use InnoDB (XtraDB) • disable query cache • enable thread pool
  19. 19. PHP-FPM • standard with PHP 5.3+ • daemonization & process management • used by Rasmus Lerdord (author of PHP)
  20. 20. PHP-FPM • pm = static • pm.max_children = {{ CPU cores * 4 }} • pm.max_children = 32 # 8c/16t • pm.max_children = 64 # 16c/32t • pm.max_children = 80 # 20c/40t
  21. 21. PHP-FPM • 5.6 is faster than 5.5 • 5.5 is faster than 5.4 • 5.4 is faster than 5.3 • 5.6 is much faster than 5.3
  22. 22. PHP-FPM • 5.6: OPcache • 5.5: OPcache • 5.4: APC • 5.3: APC
  23. 23. Redis • key-value cache & store • >= Memcached • optional persistence & hot cache • clients for almost every language • use phpredis (the C extension)
  24. 24. Resque • open source library • made by GitHub • ported to PHP (php-reque) • uses Redis
  25. 25. Load Balancer A Load Balancer B App 1 App 2 App 3 App N DB 1 DB 2 DB N Redis 1 Redis 2 Redis N DNS
  26. 26. Questions?
  27. 27. Thank you!

×