Caching and tuning fun for high scalability @ phpBenelux 2011

Wim Godden
Wim GoddenConsultant at Cu.be Solutions
Caching and tuning fun for high scalability Wim Godden Cu.be Solutions Conference Jan 28, 2011
Note about this presentation ,[object Object]
Who am I ? ,[object Object]
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 ? ,[object Object]
System/network engineers ?
Managers ?
Caching experience ?
Caching and tuning fun for high scalability Wim Godden Cu.be Solutions Conference Jan 28, 2011
Goals of this tutorial ,[object Object]
A few techniques
-> Increase reliability, performance and scalability
5 visitors/day -> 5 million visitors/day
(Don't expect miracle cure !)
Goals of this tutorial ,[object Object]
How to do stuff
How  NOT  to do stuff
LAMP
LAMP
LAMP
LAMP
Architecture
Caching
What's caching ?
What is caching ? select * from article join user on article.user_id = user.id order by created desc limit 10
Caching goals - 1 st  goal ,[object Object]
Reduce the load
Caching goals - 2 nd  goal
Some figures ,[object Object]
Avg. loading time : 200ms
Cache 10 pages
Avg. loading time : 20ms
-> Total avg. loading time : 56ms
Worth it ?
Caching goals - 3 rd  goal ,[object Object]
Users benefit -> faster page load
Wait a second... that's mostly frontend stuff !
Theory of caching DB
Theory of caching DB
Caching techniques ,[object Object]
Blogs
Full pages that don't change
Render -> Store in cache -> retrieve from cache
Caching techniques ,[object Object]
Caching techniques ,[object Object]
Usually a small block in a page
Best effect : reused on lots of pages
Can be inserted on dynamic pages
Caching techniques ,[object Object]
Caching techniques ,[object Object]
Caching techniques ,[object Object]
Resets on every insert/update/delete
Server and connection overhead ,[object Object],[object Object]
free up DB resources for more hits ! ,[object Object],[object Object]
store group of objects
Caching techniques ,[object Object]
Caching techniques ,[object Object]
CPU intensive tasks : ,[object Object]
XML file parsing
Loading CSV in an array ,[object Object]
Caching techniques ,[object Object]
Caching techniques ,[object Object]
Modification frequency ?
Retrieval frequency ?
How to find cacheable data ,[object Object]
Existing projects : ,[object Object]
Make a complete query log (don't forget to turn it off !)
Check page loading times
Caching storage - MySQL query cache ,[object Object]
Don't rely on it
Good if you have : ,[object Object]
few different queries ,[object Object],[object Object]
lots of different queries
Caching storage - Database memory tables ,[object Object]
In MySQL : memory/heap table
↔ temporary table : ,[object Object]
temporary tables are session-specific ,[object Object]
Can be joined with disk-based tables
But :  ,[object Object]
master-slave = trouble
if you don't need join -> overhead of DB software ,[object Object]
Caching storage - Opcode caching ,[object Object]
Caching storage - Opcode caching ,[object Object]
Will be in PHP core in 5.4 ? 5.5 ? 6.0 ?
PECL or packages ,[object Object]
Zend Accelerator
Caching storage - Opcode caching ,[object Object]
Will be in PHP core in 5.4 ? 5.5 ? 6.0 ?
PECL or packages ,[object Object]
Zend Accelerator
X-Cache
WinCacheForPhp PHP PHP + APC PHP + eAccelerator 42.18 req/sec 206.20 req/sec 211.49 req/sec
Caching storage - Disk ,[object Object]
Caching SQL queries : preferably not
DON'T  use NFS or other network file systems ,[object Object]
high latency
locking issues !
Caching storage - Memory disk (ramdisk) ,[object Object]
But : OS file caching makes difference minimal
Caching storage - Disk / ramdisk ,[object Object]
Limited number of files per directory ,[object Object],[object Object],[object Object]
-> Hard to scale
How will you keep them synchronized ? ,[object Object]
Caching storage - APC variable cache ,[object Object]
Store user data in memory
apc_add / apc_store to add/update
apc_fetch to retrieve
apc_delete
Fast -> huge performance impact
Caching storage - APC variable cache ,[object Object]
Store user data in memory
apc_add / apc_store to add/update
apc_fetch to retrieve
apc_delete
Fast -> huge performance impact
Session support !
Downside : ,[object Object]
restart Apache -> cache = empty
Caching storage - Memcache ,[object Object]
Distributed memory caching system
Key-value storage system ,[object Object]
Values - max. 1Mbyte
Caching storage - Memcache ,[object Object]
Distributed memory caching system
Multiple machines ↔ 1 big memory-based hash-table
Key-value storage system ,[object Object]
Values - max. 1Mbyte ,[object Object]
Memcache - where to install
Memcache - where to install
Memcache - installation & running it ,[object Object]
PECL
1 of 136

More Related Content

What's hot(20)

cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
Marc Cortinas Val1.8K views
0628阙宏宇0628阙宏宇
0628阙宏宇
zhu021.1K views
CachingCaching
Caching
Nascenia IT8.3K views
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
Jonathan Klein9.2K views
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
SiteGround.com25.4K views
HTTP caching with VarnishHTTP caching with Varnish
HTTP caching with Varnish
David de Boer1.8K views
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
Enrico Zimuel29.5K views
Sofia WP User Group PresentationSofia WP User Group Presentation
Sofia WP User Group Presentation
Daniel Kanchev540 views
Scaling symfony appsScaling symfony apps
Scaling symfony apps
Matteo Moretti4.5K views
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
Ben Ramsey10.5K views
Cassandra as MemcacheCassandra as Memcache
Cassandra as Memcache
Edward Capriolo15.2K views
Http caching basicsHttp caching basics
Http caching basics
Martin Breest663 views
Advanced HTTP CachingAdvanced HTTP Caching
Advanced HTTP Caching
Martin Breest723 views

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

More from Wim Godden(20)

Recently uploaded(20)

METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
Prity Khastgir IPR Strategic India Patent Attorney Amplify Innovation23 views
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya51 views
ThroughputThroughput
Throughput
Moisés Armani Ramírez28 views
Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum118 views
Green Leaf Consulting: Capabilities DeckGreen Leaf Consulting: Capabilities Deck
Green Leaf Consulting: Capabilities Deck
GreenLeafConsulting170 views

Caching and tuning fun for high scalability @ phpBenelux 2011