Cache all the things #DCLondon
-
Upload
digital006 -
Category
Documents
-
view
119 -
download
2
description
Transcript of Cache all the things #DCLondon
Cache All The Things
Mike Bell - @mikebell_
About Me
Mike BellLead Drupal Developer @ Ixis
@mikebell_http://drupal.org/user/189605
Exactly what things?
well errr...
everything!
No really...
Frontend:- HTML- CSS- Images- Javascript
Backend:- PHP- MySQL
So pretty much everything then!
Where to start?
Ask yourself:Why is my site slow?
a) Bad codeb) Bad serverc) It's not!
Bad Code?
Stop.
Caching will help... but it won't solve your bigger issues.
There are tools to help - xhprof
Bad Server?
So how's £5.99 a month working out for you?
Caching will help... but again you still have bigger issues.
Scale horizontally/vertically for a quick fix then work on additional caching.
It's not!
I like you!
Caching is always a good thing, except when you have to debug it...
Caching in Drupal
- Code Level (cache_get/cache_set)- APC (not covered here)- Resource caching (this get's tricky!)- DB Layer- CDNs (related to resource caching)
Code Level
Drupal has it's own caching api.
Module Developers use it!
cache_set - store data in Drupals cache tablecache_get - get data from Drupals cache table
You can even define your own cache tables!
Resource Caching
Many different types of resources
Each can be cached by different tools
Example:- Drupals CSS/JS Cache- Drupals Page Cache- Boost- Varnish
Resource Caching
Drupal default: CSS/JS and Page
(taken from mikebell.io - ooppss!)
Resource Caching - Boost
Boost - http://drupal.org/project/boost
Static caching for all Drupal Assets
Anonymous users only
Ideal for shared hosting environments
Potentially the easiest to setup
Resource Caching - Varnish
Application Accelerator
Linux Only
Caches resources based on initial view
Anonymous only - very picky with sessions and cookies
Insanely Powerful
Resource Caching - Varnish
Advanced setup - requires additional module and VCL for Drupal- http://drupal.org/project/varnish
Granular ttls (time to live)
Specific resource (image/css) and page element! All available through VCL config.
Resource Caching - Varnish
Cache Stores- RAM- Disk
Ram - super fast - requires a lot of ramDisk - fast - disk space is rarely an issue
Data Caching - memcached
Data and Database caching layer
Caches cache... (and things!)
Data Caching - memcachedExample:Core cache - core cache tables (cache_*)
Moved into memcached and shared between multiple instances across multiple servers
Simple api makes getting and setting easy
Drupal requires - http://drupal.org/project/memcache and pecl extension
3rd Party Caching - Akamai
One of the biggest caching providers
A high chance you've experienced Akamai today without realising it.
Static cache of resourcesContent Distribution Network100+ Edge servers all over the world
3rd Party Caching - Akamai
Coverage for DDOS attacks- Active monitoring and defense
Advanced redirection rules through control panel
It's not cheap!
It's also pretty magical.
3rd Party Caching - Cloudflare
Similar to Akamai
Smaller scale
Emphasis on security and DDOS protection
Content Distribution Network
CDNs for short
Offload resource handling to external provider- Images- Video- Audio- Large files
Syndicate content around the world
Content Distribution Network
Why use a CDN?- Content is delivered quicker-- Latency cut down
Pricing is granular - pay as you go type deal
Amazon + Rackspace Cloud Files
How does it all fit together?
What happens when it all goes wrong?
Caching to the rescue!
Each layer provides protection
3rd Party - shield 99% of anon trafficVarnish - the rest
Anonymous users should never know your site has issues.
Debugging Tips
Configure different urls for different platforms- Easier to identify what cache layer has an issue
Don't be afraid to flush caches- Your backend should be able to cope with it
Analyse headers! Drupal and Varnish provide a lot of info
Akamai information can be gleaned from additional http headers.
Debugging Tips
Monitor each layer- Icinga- Pingdom
Any Questions?
Slide designs by Ritch Partridge (@ritchpartridge)