steve corona: scaling lamp doesn't have to suck

Post on 08-May-2015

3.366 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

"I went from sleeping in front of my laptop, restarting apache every hour, to automatically scaling servers from my phone." More at http://webexpo.net/prague2013/talk/scaling-lamp-doesnt-have-to-suck/

TRANSCRIPT

scaling LAMPdoesn’t have to

suck!@stevencorona

(400 million api calls/day)

(3 billion photos)

let’s learn how to scale php

...in 40 minutes

scaling is...architecting your app for millions of users

scaling is...

an art, not a science

scaling is...

NOT CODEabout infrastructure

your code is fast enough

LAMPLINUX

APACHEMYSQL

PHP

problems•single points of failure•apache+mod_php memory hog•slow linux default settings•can’t do work in the background

a better LAMPLINUX +TUNING

NGINXPERCONAPHP-FPM

NSQREDIS

nginxloadbalancer

nginxphp-fpm

MySQLMaster

nginxphp-fpm

nginxphp-fpm

nsq

MySQLReadOnly

redis

tuning linux•linux is mostly sane•use latest kernel•distro doesn’t matter•(i like ubuntu)

top 3 settingsopen_files

network/sysctl tuningi/o scheduler

most settings you find online are outdated

open filesdefault is 1024

on linux, each socket = open file

/etc/security/limits.confsoft nofile 999999hard nofile 999999

sysctl tuningthousands of settings

newer kernels autotune network

/etc/sysctl.confnet.core.somaxconn=999999

net.ipv4.ip_local_port_range=2000 62000net.ipv4.tcp_tw_recycle=1

vm.swapiness=0

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 apacheeasy + sane config

nginx.org

nginxmost popular webserver

of top 1000 sites

15,000 requests/second with 20% CPU and100MB RAM

nginx

nginxload balancerhttp cache

fastcgi proxyweb server

php

php-fpm is kingstandard with php5.3

php-fpmuse static worker pool

4x number of CPU cores

pm=staticpm.max_children=128

phpphp 5.5 is much faster

than 5.4 and 5.3

USE IT!

php

php 5.5 includes Zend Optimizer+ (no more APC)

10-20% faster than APC in real world

php

horizontal scalingwatch out for sessions!

php + mysqlmysql persistent

connections are GOOD to use.

despite what the internet says

php + mysql

20-25% faster for first query

after that it doesn’t matter

php + mysqlwatch out for thundering

herdmysql’s max_connections

2(pm.max_children * # servers)

php + mysqlturn on mysql protocol

compression

 $m = mysqli_init(); $m->real_connect($username...., MYSQL_CLIENT_COMPRESS);

perconaopen 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

perconawatch out for NUMA

innodb_buffer_pool_populate=1flush_caches=1numa_interleave=1

perconastop wasting time

use SSDs

went from15 mysql servers to 2 using SSD

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 EC2use HVM instances

redislots of php libraries

use pecl-redisc extension

pecl install redis

nsqmessage queue server in golang by

bit.ly

we use it to process 370 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 MYSQLAS A WORK QUEUE!

don’t scale code

your code is fast enough

scale infrastructure

thanks!

follow me on twitter@stevencorona

top related