Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Scaling LAMP doesn't have to suck
Slide 2
Slide 2 text
Sebastian Grodzicki CTO @ GoldenLine ~100 req/s ~4.7M UU
Slide 3
Slide 3 text
#DevOps
Slide 4
Slide 4 text
LAMP • Linux • Apache • MySQL • PHP
Slide 5
Slide 5 text
Scaling LAMP • shared hosting • VPS • dedicated server
Slide 6
Slide 6 text
Scaling LAMP • split LAMP into LM + LAP • use virtual machines or Docker • forget 127.0.0.1 (AKA localhost) • forget about local storage
Slide 7
Slide 7 text
A better LAMP • Linux (tuned) • Apache Nginx • MySQL Percona Server • PHP PHP-FPM • Redis • Resque
Slide 8
Slide 8 text
Linux (tuned) • Linux is mostly sane • use latest kernel • distribution doesn’t matter • (I like Debian)
Slide 9
Slide 9 text
Tune Linux • open_files • network/sysctl • i/o scheduler
Slide 10
Slide 10 text
Linux: open_files • default: 1024 (ulimit -n) • soft nofile 999999 • hard nofile 999999
Slide 11
Slide 11 text
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)
Slide 12
Slide 12 text
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
Slide 13
Slide 13 text
Nginx • open-source HTTP server • swap out Apache • easy + sane config
Slide 14
Slide 14 text
Nginx 21k req/s @ 10% CPU & 160 MB RAM
Slide 15
Slide 15 text
Nginx • load balancer • reverse proxy • content caching • streaming media • web server
Slide 16
Slide 16 text
Percona Server • open source MySQL fork • patches from Twitter and Google • drop-in MySQL replacement • faster at scale, more reliable
Slide 17
Slide 17 text
MySQL vs Percona new transactions per minute
Slide 18
Slide 18 text
Percona Server • only use InnoDB (XtraDB) • disable query cache • enable thread pool
Slide 19
Slide 19 text
PHP-FPM • standard with PHP 5.3+ • daemonization & process management • used by Rasmus Lerdord (author of PHP)
Slide 20
Slide 20 text
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
Slide 21
Slide 21 text
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
Slide 22
Slide 22 text
PHP-FPM • 5.6: OPcache • 5.5: OPcache • 5.4: APC • 5.3: APC
Slide 23
Slide 23 text
Redis • key-value cache & store • >= Memcached • optional persistence & hot cache • clients for almost every language • use phpredis (the C extension)
Slide 24
Slide 24 text
Resque • open source library • made by GitHub • ported to PHP (php-reque) • uses Redis
Slide 25
Slide 25 text
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
Slide 26
Slide 26 text
Questions?
Slide 27
Slide 27 text
Thank you!