Caching and tuning fun for high scalability @ FOSDEM 2012

Embed Size (px)

Citation preview

Caching and tuning funfor high scalability

Wim GoddenCu.be Solutions

Who am I ?

Wim Godden (@wimgtr)

Owner of Cu.be Solutions (http://cu.be)

Open Source developer since 1997

Developer of OpenX

Zend Certified Engineer

Zend Framework Certified Engineer

MySQL Certified Developer

Who are you ?

Developers ?

System/network engineers ?

Managers ?

Caching experience ?

Caching and tuning funfor high scalability

Wim GoddenCu.be Solutions

Goals of this tutorial

Everything about caching and tuning

A few techniquesHow-to

How-NOT-to

Increase reliability, performance and scalability

5 visitors/day 5 million visitors/day

(Don't expect miracle cure !)

LAMP

Architecture

Our base benchmark

Apachebench = useful enough

Result ?

Single webserverProxy

StaticPHPStaticPHP

Apache + PHP390017.5670017.5

Limit :CPU, networkor disk

Limit :database

Caching

What is caching ?

CACHE

What is caching ?

x = 5, y = 2n = 50Same resultCACHE

select*fromarticlejoin useron article.user_id = user.idorder bycreated desclimit10

Doesn't changeall the time

Theory of caching

DB

Cache$data = get('key')falseGET /pagePageselect data from table$data = returned resultset('key', $data)if ($data == false)

Theory of caching

DB

Cache

HIT

Caching techniques

#1 : Store entire pages#2 : Store part of a page (block)#3 : Store data retrieval (SQL ?)#4 : Store complex processing result#? : Your call !

When you have data, think :Creating time ?

Modification frequency ?

Retrieval frequency ?

How to find cacheable data

New projects : start from 'cache everything'

Existing projects :Look at MySQL slow query log

Make a complete query log (don't forget to turn it off !)

Check page loading times

Caching storage - Disk

Data with few updates : good

Caching SQL queries : preferably not

DON'T use NFS or other network file systemsespecially for sessions

locking issues !

high latency

Caching storage - Disk / ramdisk

Local5 Webservers 5 local caches Hard to scale

How will you keep them synchronized ? Don't say NFS or rsync !

Caching storage - Memcache(d)

Facebook, Twitter, YouTube, need we say more ?

Distributed memory caching system

Multiple machines 1 big memory-based hash-table

Key-value storage systemKeys - max. 250bytes

Values - max. 1Mbyte

Caching storage - Memcache(d)

Facebook, Twitter, YouTube, need we say more ?

Distributed memory caching system

Multiple machines 1 big memory-based hash-table

Key-value storage systemKeys - max. 250bytes

Values - max. 1Mbyte

Extremely fast... non-blocking, UDP (!)

Memcache - where to install

Memcache - where to install

Memcache - installation & running it

InstallationDistribution package

PECL

Windows : binaries

RunningNo config-files

memcached -d -m -l -p

ex. : memcached -d -m 2048 -l 172.16.1.91 -p 11211

Caching storage - Memcache - some notes

Not fault-tolerantIt's a cache !

Lose session data

Lose shopping cart data

...

Caching storage - Memcache - some notes

Not fault-tolerantIt's a cache !

Lose session data

Lose shopping cart data

Firewall your Memcache port !

Memcache in code