27
Scaling LAMP doesn't have to suck

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

  • Upload
    proidea

  • View
    174

  • Download
    1

Embed Size (px)

Citation preview

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

Scaling LAMPdoesn't have to suck

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

SebastianGrodzicki

CTO @ GoldenLine

~100 req/s ~4.7M UU

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

#DevOps

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

LAMP

• Linux

• Apache

• MySQL

• PHP

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

Scaling LAMP

• shared hosting

• VPS

• dedicated server

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

Scaling LAMP

• split LAMP into LM + LAP

• use virtual machines or Docker

• forget 127.0.0.1 (AKA localhost)

• forget about local storage

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

A better LAMP

• Linux (tuned)

• Apache Nginx

• MySQL Percona Server

• PHP PHP-FPM

• Redis

• Resque

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

Linux (tuned)

• Linux is mostly sane

• use latest kernel

• distribution doesn’t matter

• (I like Debian)

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

Tune Linux

• open_files

• network/sysctl

• i/o scheduler

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

Linux: open_files

• default: 1024 (ulimit -n)

• soft nofile 999999

• hard nofile 999999

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

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)

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

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

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

Nginx

• open-source HTTP server

• swap out Apache

• easy + sane config

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

Nginx21k req/s @ 10% CPU & 160 MB RAM

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

Nginx

• load balancer

• reverse proxy

• content caching

• streaming media

• web server

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

Percona Server

• open source MySQL fork

• patches from Twitter and Google

• drop-in MySQL replacement

• faster at scale, more reliable

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

MySQL vs Perconanew transactions per minute

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

Percona Server

• only use InnoDB (XtraDB)

• disable query cache

• enable thread pool

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

PHP-FPM

• standard with PHP 5.3+

• daemonization & process management

• used by Rasmus Lerdord (author of PHP)

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

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

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

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

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

PHP-FPM

• 5.6: OPcache

• 5.5: OPcache

• 5.4: APC

• 5.3: APC

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

Redis

• key-value cache & store

• >= Memcached

• optional persistence & hot cache

• clients for almost every language

• use phpredis (the C extension)

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

Resque

• open source library

• made by GitHub

• ported to PHP (php-reque)

• uses Redis

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

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

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

Questions?

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

Thank you!