The document discusses techniques for optimizing performance on Drupal websites, including caching at various levels (PHP opcode, computations, data, entities), using content delivery networks and parallelization for assets, optimizing browser rendering of JavaScript and CSS, compressing files, keeping the Drupal architecture and modules simple, and tools for analyzing performance at the browser, Drupal, PHP and system levels.
2. 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
4. 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, …)
jbguerraz@skilld.fr
5. Cache
How should we cache ?
PHP (opcode) :
●
●
// allocate one segment of 32Mb
apc.shm_segments=1
apc.shm_size=32
// do not check if php file was updated
apc.stat= 0
APC
Eaccelerator (a bit faster,
seg fault)
jbguerraz@skilld.fr
// never expire
apc.ttl = 0
// use kernel anonymous memory
apc.mmap_file_mask = /dev/zero.
6. Cache
How should we cache ?
function mymodule_complex_calculation_crazy_cache() {
static $cache ;
Computations (functions results) :
if (isset($cache)) {
return $cache ;
}
($cache = &drupal_static(__FUNCTION__)) {
●
drupal_static (sometime static if big ifreturn $cache;
amount of calls within a page load) }
if ($cache = cache_get('my_cache_item', 'my_cache_bin')) {
$cache = $cache->data;
}
●
cache_set / cache_get (use your own else {
heavy calculations that kills
bin if lot of data to store and/or need // some = complex_calculation(); kitten
$cache
cache_set('my_cache_item', $cache, 'my_cache_bin');
more control over your cache)
}
return $cache ;
}
jbguerraz@skilld.fr
7. Cache
How should we cache ?
Datas (views, DB requests) :
●
Views cache
●
Views per user cache
●
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
Field
Type
Null
cid
Own cache bin for DB requests (if
somehow there is a good reason
to request DB directly)
varchar(255)
no
data
longblob
yes
expire
int
no
created
int
no
headers
text
yes
serialized smallint
jbguerraz@skilld.fr
no
8. Cache
How should we cache ?
Entities (nodes, comments, taxonomy terms,
user profiles,…) :
Entity cache
Entity cache
seconds
●
Load 1 000 users
50
45
40
35
30
25
20
15
10
5
0
First load
Next loads
No entity cache
jbguerraz@skilld.fr
Entity cache
9. Cache
How should we cache ?
Images (imagecache/styles) :
●
ImageCache
●
ImageCache External
jbguerraz@skilld.fr
10. Cache
How should we cache ?
HTML (page, block, panel, pane, views) :
●
Panels Page Cache
●
Panels Hash Cache
●
Varnish
●
Varnish ESI
jbguerraz@skilld.fr
11. Cache
How should we cache ?
Any static ressource (CSS, JS, SWF, SVG,
PDF, ZIP, Video, Sound, …) :
●
Varnish
●
Nginx
●
CDN far-future
jbguerraz@skilld.fr
14. 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)
jbguerraz@skilld.fr
15. Upload & Download
Aggregates
JS (Advanced aggregate)
●
CSS (Advanced aggregate)
●
Images & CSS (CSS
embeded image)
●
Images (spritesheets)
●
jbguerraz@skilld.fr
Note :
Sprites are now obselete, use CSS
embeded image instead
(for IE, images <32Kb can be
embeded)
18. Browser rendering
CSS
Translate3D, no DOM position change
●
Pay attention to selectors performances ! No
CSS3 selectors (great but slow)
●
Avoid blinking > no JS to hide an element on
load, hide by CSS and show from JS
(perception matters!)
●
jbguerraz@skilld.fr
19. Compression
What should we compress ?
Images
●
CSS
●
JS
●
HTML
●
«Any» static file
●
jbguerraz@skilld.fr
20. Compression
How should we compress ?
Images
●
Imageapi optimize
●
jpegtran
●
advpng
jbguerraz@skilld.fr
21. Compression
How should we compress ?
CSS
Advagg CSS compress
●
CSS Compressor
●
●
●
faster than CSSTidy
gzip
jbguerraz@skilld.fr
22. Compression
How should we compress ?
JS
Advagg JS compress
●
JSMin
●
●
●
faster than JSMin+
Gzip
jbguerraz@skilld.fr
25. 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
●
jbguerraz@skilld.fr
26. 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
jbguerraz@skilld.fr