drupal camp kiev 2012 - high performance drupal web sites
TRANSCRIPT
High PerformanceDrupal Web Sites
360
Who's that punk ?!
A French nerd!
Used to manage complex IT projects for the last 10 years
And many more nights on performances issues ... :)
... who just created his own company
Summary
Cache
Upload & Download
Browser rendering
Compression
Drupal pages architecture
Analyze
Cache
What should we cache?
EVERY POSSIBLE THING!!!
PHP (opcode)
Computations (functions results)
Datas (views, DB requests)
Entities & Fields (nodes, comments, taxonomy terms, user profiles,)
Images (imagecache/styles)
HTML (page, block, panel, pane, views)
Any static ressource (CSS, JS, SWF, SVG, PDF, ZIP, Video, Sound,)
Cache
How should we cache?
PHP (opcode):
APC
Eaccelerator (a bit faster, seg fault)
// allocate one segment of 32Mbapc.shm_segments=1apc.shm_size=32
// do not check if php file was updatedapc.stat= 0
// never expireapc.ttl = 0
// use kernel anonymous memoryapc.mmap_file_mask = /dev/zero.
Cache
function mymodule_complex_calculation_crazy_cache() { static $cache; if (isset($cache)) { return $cache; } if ($cache = &drupal_static(__FUNCTION__)) { return $cache; } if ($cache = cache_get('my_cache_item', 'my_cache_bin')) { $cache = $cache->data; } else { // some heavy calculations that kills kitten $cache = complex_calculation(); cache_set('my_cache_item', $cache, 'my_cache_bin'); } return $cache;}
How should we cache?
Computations (functions results):
drupal_static (sometime static if big amount of calls within a page load)
cache_set / cache_get (use your own bin if lot of data to store and/or need more control over your cache)
Cache
How should we cache?
Datas (views, DB requests): Views cache
Views per user cache
Own cache bin for DB requests (if somehow there is a good reason to request DB directly)
Note:
A custom cache bin require, at module install, to create a new cache table using the same schema as core cache tables (see table below).Copy/paste from: includes/system.install
FieldTypeNull
cidvarchar(255)no
datalongblobyes
expireintno
createdintno
headerstextyes
serializedsmallintno
Cache
How should we cache?
Entities (nodes, comments, taxonomy terms, user profiles,): Entity cache
Cache
How should we cache?
Images (imagecache/styles): ImageCache
ImageCache External
Cache
How should we cache?
HTML (page, block, panel, pane, views): Panels Page Cache
Panels Hash Cache
Varnish
Varnish ESI
Cache
How should we cache?
Any static ressource (CSS, JS, SWF, SVG, PDF, ZIP, Video, Sound,): Varnish
Nginx
CDN far-future
Cache
What cache backends?
http://janezurevc.name/static/bcn_cache
Cache
What about cache invalidation?
Cache actions
Cachetags
Views content cache
Expire
Entity cache flusher
Upload & Download
Cookie free domains
CDN module in order to use static resources dedicated domain(s) which differ from main domain (for instance, static.mysite.com)
$cookie_domain have to be set to main domain in settings.php (for instance www.mysite.com)
Upload & Download
Aggregates
JS (Advanced aggregate)
CSS (Advanced aggregate)
Images & CSS (CSS embeded image)
Images (spritesheets)
Note:
Sprites are now obselete, use CSS embeded image instead
(for IE, images no JS to hide an element on load, hide by CSS and show from JS (perception matters!)
Compression
What should we compress ?
Images
CSS
JS
HTML
Any static file
Compression
How should we compress ?
Images
Imageapi optimizejpegtran
advpng
Compression
How should we compress ?
CSS
Advagg CSS compress
CSS Compressorfaster than CSSTidy
gzip
Compression
How should we compress ?
JS
Advagg JS compress
JSMinfaster than JSMin+
Gzip
Compression
How should we compress ?
HTML
Gzip
Compression
How should we compress ?
Any static files
Gzip
Drupal pages architecture
How to build a performant page ?
USE AS FEW MODULES AS POSSIBLE !
Search_api (solr, mongo)
Mongodb
Redis
Memcache
Elysia cron
Panels
Panels everywhere
Views
Rules
Entities
Drupal pages architecture
Why homogeneity maters ?
Blocks, panes, pick one !
One single way of managing blocks helps using ESI caching for instance; it also makes easier the cache invalidation management for these blocks.
Keep it simple : one API to implement
Analyze
Browser level
Gtmetrix.com
Yslow
Firebug
Chrome / Safari developer tools
Whichloadsfaster.com
Analyze
Drupal level
Devel
Watchdog (redirected to syslog if needed on live server)
Analyze
PHP level
FirePHP / ChromePHP
Xhprof (eventually in addition to Xdebug)
PHP error log
PHP-FPM slow logs
MySQL Slow query logs
Analyze
System level
strace
tcpdump & wireshark
Wanna get these slides ?Search for jbguerraz on Slideshare ;)
Spasibo bolshoe !
Your time now, any question ?
Entity cacheLoad 1 000 userssecondsFirst loadNext loads
No entity cache3916
Entity cache430.558