Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scaling LAMP

Scaling LAMP

Scaling LAMP doesn't have to suck

Sebastian Grodzicki

April 20, 2015
Tweet

More Decks by Sebastian Grodzicki

Other Decks in Technology

Transcript

  1. Scaling LAMP • split LAMP into LM + LAP •

    use virtual machines or Docker • forget 127.0.0.1 (AKA localhost) • forget about local storage
  2. A better LAMP • Linux (tuned) • Apache Nginx •

    MySQL Percona Server • PHP PHP-FPM • Redis • Resque
  3. Linux (tuned) • Linux is mostly sane • use latest

    kernel • distribution doesn’t matter • (I like Debian)
  4. 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)
  5. 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
  6. Percona Server • open source MySQL fork • patches from

    Twitter and Google • drop-in MySQL replacement • faster at scale, more reliable
  7. PHP-FPM • standard with PHP 5.3+ • daemonization & process

    management • used by Rasmus Lerdord (author of PHP)
  8. 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
  9. 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
  10. Redis • key-value cache & store • >= Memcached •

    optional persistence & hot cache • clients for almost every language • use phpredis (the C extension)
  11. Resque • open source library • made by GitHub •

    ported to PHP (php-reque) • uses Redis
  12. 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