SlideShare a Scribd company logo
Caching and tuning fun for high scalability Wim Godden Cu.be Solutions
Who am I ? Wim Godden (@wimgtr)
Owner of Cu.be Solutions (http://cu.be)
PHP 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 fun for high scalability Wim Godden Cu.be Solutions
Goals of this tutorial Everything about caching and tuning
A few techniques How-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 ?
Caching
What is caching ?
What is caching ? select * from article join user on article.user_id = user.id order by created desc limit 10
Theory of caching if ($data == false) DB
Theory of caching DB
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 - MySQL query cache Use it
Don't rely on it
Bad if you have : lots of insert/update/delete
lots of different queries
Caching storage - Disk Data with few updates : good
Caching SQL queries : preferably not
DON'T  use NFS or other network file systems especially for sessions
locking issues !
high latency
Caching storage - Disk / ramdisk Local 5 Webservers -> 5 local caches
-> Hard to scale
How will you keep them synchronized ? -> Don't say NFS or rsync !
Caching storage - Memcache Facebook, Twitter, Slashdot, … -> need we say more ?
Distributed memory caching system
Multiple machines ↔ 1 big memory-based hash-table
Key-value storage system Keys - max. 250bytes
Values - max. 1Mbyte
Caching storage - Memcache Facebook, Twitter, Slashdot, … -> need we say more ?
Distributed memory caching system
Multiple machines ↔ 1 big memory-based hash-table
Key-value storage system Keys - max. 250bytes
Values - max. 1Mbyte Extremely fast... non-blocking, UDP (!)
Memcache - where to install
Memcache - where to install
Memcache - installation & running it Installation Distribution package
PECL
Windows : binaries Running No config-files
memcached -d -m <mem> -l <ip> -p <port>
ex. : memcached -d -m 2048 -l 172.16.1.91 -p 11211
Caching storage - Memcache - some notes Not fault-tolerant It's a cache !
Lose session data
Lose shopping cart data
...
Caching storage - Memcache - some notes Not fault-tolerant It's a cache !
Lose session data
Lose shopping cart data
… Firewall your Memcache port !
Memcache in code <?php $memcache =  new  Memcache(); $memcache->addServer( '172.16.0.1' , 11211); $memcache->addServer( '172.16.0.2' , 11211); $myData = $memcache->get( 'myKey' ); if  ($myData ===  false ) { $myData = GetMyDataFromDB(); // Put it in Memcache as 'myKey', without compression, with no expiration $memcache->set( 'myKey' , $myData,  false , 0); } echo  $myData;
Where's the data ? Memcache client decides (!)
2 hashing algorithms : Traditional Server failure -> all data must be rehashed Consistent Server failure -> 1/x of data must be rehashed (x = # of servers)
Benchmark with Memcache
Memcache slabs (or why Memcache says it's full when it's not) Multiple slabs of different sizes : Slab 1 : 400 bytes
Slab 2 : 480 bytes (400 * 1.2)
Slab 3 : 576 bytes (480 * 1.2) (and so on...) Multiplier (1.2 here) can be configured
Store a lot of very large objects
-> Large slabs : full
-> Rest : free
-> Eviction of data !

More Related Content

ODP
Caching and tuning fun for high scalability
ODP
Caching and tuning fun for high scalability @ FOSDEM 2012
ODP
Caching and tuning fun for high scalability @ phpBenelux 2011
ODP
Beyond PHP - it's not (just) about the code
ODP
Caching and tuning fun for high scalability
ODP
phptek13 - Caching and tuning fun tutorial
ODP
Caching and tuning fun for high scalability
ODP
Beyond PHP - It's not (just) about the code
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ phpBenelux 2011
Beyond PHP - it's not (just) about the code
Caching and tuning fun for high scalability
phptek13 - Caching and tuning fun tutorial
Caching and tuning fun for high scalability
Beyond PHP - It's not (just) about the code

What's hot (20)

ODP
Beyond php - it's not (just) about the code
ODP
Beyond php - it's not (just) about the code
ODP
Caching and tuning fun for high scalability
ODP
Caching and tuning fun for high scalability @ 4Developers
ODP
Beyond php - it's not (just) about the code
PDF
Memcached Presentation
PPT
Memcache
PPTX
High performance WordPress
PDF
Top Node.js Metrics to Watch
PDF
Scaling symfony apps
PPT
Zend Con 2008 Slides
PDF
Ansible : what's ansible & use case by REX
ODP
MySQL Scaling Presentation
PDF
Scaling Rails with Memcached
PPT
0628阙宏宇
PPTX
Http caching basics
PPTX
Advanced HTTP Caching
PDF
Feed Burner Scalability
PDF
VUG5: Varnish at Opera Software
PDF
Scaling Twitter 12758
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability @ 4Developers
Beyond php - it's not (just) about the code
Memcached Presentation
Memcache
High performance WordPress
Top Node.js Metrics to Watch
Scaling symfony apps
Zend Con 2008 Slides
Ansible : what's ansible & use case by REX
MySQL Scaling Presentation
Scaling Rails with Memcached
0628阙宏宇
Http caching basics
Advanced HTTP Caching
Feed Burner Scalability
VUG5: Varnish at Opera Software
Scaling Twitter 12758
Ad

Similar to Caching and tuning fun for high scalability @ PHPTour (20)

ODP
Caching and tuning fun for high scalability @ FrOSCon 2011
ODP
Caching and tuning fun for high scalability
PDF
Top ten-list
PDF
Clug 2012 March web server optimisation
PPT
Tips for a Faster Website
PPTX
Anthony Somerset - Site Speed = Success!
ODP
Clug 2011 March web server optimisation
KEY
Introduction to memcached
PPTX
Joomla! Performance on Steroids
KEY
Caching: A Guided Tour - 10/12/2010
PDF
Zend Server Data Caching
ODP
Experience In Building Scalable Web Sites Through Infrastructure's View
PDF
Enhancing scalability with intelligent caching
PPTX
Turbocharging php applications with zend server
PDF
Turbocharging php applications with zend server (workshop)
PDF
High Performance Drupal Sites
PPT
Caching Data For Performance
PPT
Startups to Scale
PPTX
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability
Top ten-list
Clug 2012 March web server optimisation
Tips for a Faster Website
Anthony Somerset - Site Speed = Success!
Clug 2011 March web server optimisation
Introduction to memcached
Joomla! Performance on Steroids
Caching: A Guided Tour - 10/12/2010
Zend Server Data Caching
Experience In Building Scalable Web Sites Through Infrastructure's View
Enhancing scalability with intelligent caching
Turbocharging php applications with zend server
Turbocharging php applications with zend server (workshop)
High Performance Drupal Sites
Caching Data For Performance
Startups to Scale
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Ad

More from Wim Godden (20)

PDF
Beyond php - it's not (just) about the code
PDF
Bringing bright ideas to life
PDF
The why and how of moving to php 8
PDF
The why and how of moving to php 7
PDF
My app is secure... I think
PDF
My app is secure... I think
PDF
Building interactivity with websockets
PDF
Bringing bright ideas to life
ODP
Your app lives on the network - networking for web developers
ODP
The why and how of moving to php 7.x
ODP
The why and how of moving to php 7.x
ODP
Beyond php - it's not (just) about the code
ODP
My app is secure... I think
ODP
Building interactivity with websockets
ODP
Your app lives on the network - networking for web developers
ODP
My app is secure... I think
ODP
My app is secure... I think
ODP
The promise of asynchronous php
ODP
My app is secure... I think
ODP
My app is secure... I think
Beyond php - it's not (just) about the code
Bringing bright ideas to life
The why and how of moving to php 8
The why and how of moving to php 7
My app is secure... I think
My app is secure... I think
Building interactivity with websockets
Bringing bright ideas to life
Your app lives on the network - networking for web developers
The why and how of moving to php 7.x
The why and how of moving to php 7.x
Beyond php - it's not (just) about the code
My app is secure... I think
Building interactivity with websockets
Your app lives on the network - networking for web developers
My app is secure... I think
My app is secure... I think
The promise of asynchronous php
My app is secure... I think
My app is secure... I think

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation theory and applications.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Mushroom cultivation and it's methods.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
TLE Review Electricity (Electricity).pptx
PPT
Teaching material agriculture food technology
PDF
Approach and Philosophy of On baking technology
PPTX
Machine Learning_overview_presentation.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
Encapsulation_ Review paper, used for researhc scholars
Assigned Numbers - 2025 - Bluetooth® Document
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25-Week II
A comparative study of natural language inference in Swahili using monolingua...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cloud_computing_Infrastucture_as_cloud_p
Mushroom cultivation and it's methods.pdf
A Presentation on Artificial Intelligence
TLE Review Electricity (Electricity).pptx
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Machine Learning_overview_presentation.pptx
A comparative analysis of optical character recognition models for extracting...
OMC Textile Division Presentation 2021.pptx
Programs and apps: productivity, graphics, security and other tools

Caching and tuning fun for high scalability @ PHPTour