scaling lamp doesn't have to suck
DESCRIPTION
Scale PHP Effortlessly— Learn the 80/20 of owning your LAMP stack and get back to coding! I spent a year sleeping next to my laptop, rolling over to restart Apache, as I scaled Twitpic to 50m users. Save your sanity and learn from my mistakes.TRANSCRIPT
scaling LAMPdoesn’t have to
suck!@stevencorona
(800 million api calls/day)
let’s learn how to scale php
!
...in 40 minutes
LAMPLINUX
APACHEMYSQL
PHP
a better LAMPLINUX +TUNING
NGINXPHP-FPM
PERCONA
NSQREDIS
nginx loadbalancer
nginx php-fpm
MySQL Master
nginx php-fpm
nginx php-fpm
nsq
MySQL Slavecache
MySQL Slave
tuning linux•linux is mostly sane •use latest kernel •distro doesn’t matter •(i like ubuntu)
top 3 settingsopen_files
network/sysctl tuning i/o scheduler
!
most settings you find online are outdated
open filesdefault is 1024
on linux, each socket = open file !
/etc/security/limits.conf!soft nofile 65535!hard nofile 65535
sysctl tuning!
thousands of settings newer kernels autotune network
!
/etc/sysctl.conf!net.core.somaxconn=65536!
net.ipv4.ip_local_port_range=2000 62000!
i/o schedulerlinux has swappable scheduler
default is cfq !
$ echo “deadline” > \!/sys/block/sda/queue/scheduler
!
+50% IOPS on MySQL
nginxopen-source HTTP server
swap out apache easy + sane config
nginx.org
nginxmost popular webserver
of top 1000 sites !
15,000 requests/second with 20% CPU and100MB RAM
nginx
nginxload balancer http cache
fastcgi proxy web server
php
php-fpm is king standard with php5.3
php-fpmuse static worker pool
4x number of CPU cores !
pm=static!pm.max_children=128
phpphp 5.5 is much faster
than 5.4 and 5.3 !
USE IT!
php!
php 5.5 includes Zend Opcache
(no more APC) !
10-20% faster than APC in real world
php
horizontal scaling watch out for sessions!
php + mysqlmysql persistent
connections are GOOD to use.
!
despite what the internet says
percona!
open source mysql fork !
patches from twitter and google
percona.com
perconadrop-in replacement
!
faster at scale, more reliable
percona
new transactions per minute (more is better)
percona•only use innodb •disable query cache •enable thread pool
thread_handling=pool-of-threads!
perconastop wasting time
use SSDs !
redisin the old days, we used
memcache !
redis is better !
redis.io
redis•data persisted to disk •hot cache •500,000 GET/second
redisconfig is great out of box
!
avoid stalls on EC2 use HVM instances
redislots of php libraries
!
use pecl-redis c extension
pecl install redis
nsqmessage queue server in golang by
bit.ly !
we use it to process 800 million events/day
!
https://github.com/bitly/nsq
nsq•nsqphp is best php library •pub/sub model •do work async •api calls •defer long-running work
!
https://github.com/davegardnerisme/nsqphp
nsq
nsq
DON’T USE MYSQL AS A WORK QUEUE!
don’t scale code!
your code is fast enough !
scale infrastructure