Drupalcamp performance

76
WWLLC Create Drupal sites with good performance What Would Lucky Luke Code?

description

What Would Lucky Luke Code? A walkthrough of the tools and tricks we use to maximize performance when building Drupal sites, both backend and frontend

Transcript of Drupalcamp performance

Page 1: Drupalcamp performance

WWLLC

Create Drupal sites with good

performance

What Would Lucky Luke Code

HenrikDeveloperMostly backendFrontHenrik

FrankWeb designerMostly front-endfragje

Per Andreacute RoslashnsenCIOChief Innovation Officer

Fredrik PausCOOProject Manager

Thor Andreacute GretlandSupport amp Training

Geir GullandCEO Web strategist

Frank GjertsenWeb Designer

Eacutelio CroacuteWeb Developer

Roberto OrnelasCTO Senior developer

Heacutelder MendesWeb Designer

Elisabeth GullandAccountant

Henrik AkselsenJSMobile UX

Jan-Helge HansenInfrastructure support

Faacutebio NevesWeb developer

Marco Fernandes Senior Web developer

Bruno CamposWeb developer

WilmaQA Engineer )

The frontkom family

Fredrikstad | Madeira

Agenda

Why performance Analysis Frontend Server configuration Backend Your inputs

SHOWTIME

We got fast internet connections Powerful computers Shiny large screens

hellipbut wait we got mobilehellipand bad mobile connectionshellipand emerging markets which are mobile only

Why performance now

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 2: Drupalcamp performance

HenrikDeveloperMostly backendFrontHenrik

FrankWeb designerMostly front-endfragje

Per Andreacute RoslashnsenCIOChief Innovation Officer

Fredrik PausCOOProject Manager

Thor Andreacute GretlandSupport amp Training

Geir GullandCEO Web strategist

Frank GjertsenWeb Designer

Eacutelio CroacuteWeb Developer

Roberto OrnelasCTO Senior developer

Heacutelder MendesWeb Designer

Elisabeth GullandAccountant

Henrik AkselsenJSMobile UX

Jan-Helge HansenInfrastructure support

Faacutebio NevesWeb developer

Marco Fernandes Senior Web developer

Bruno CamposWeb developer

WilmaQA Engineer )

The frontkom family

Fredrikstad | Madeira

Agenda

Why performance Analysis Frontend Server configuration Backend Your inputs

SHOWTIME

We got fast internet connections Powerful computers Shiny large screens

hellipbut wait we got mobilehellipand bad mobile connectionshellipand emerging markets which are mobile only

Why performance now

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 3: Drupalcamp performance

FrankWeb designerMostly front-endfragje

Per Andreacute RoslashnsenCIOChief Innovation Officer

Fredrik PausCOOProject Manager

Thor Andreacute GretlandSupport amp Training

Geir GullandCEO Web strategist

Frank GjertsenWeb Designer

Eacutelio CroacuteWeb Developer

Roberto OrnelasCTO Senior developer

Heacutelder MendesWeb Designer

Elisabeth GullandAccountant

Henrik AkselsenJSMobile UX

Jan-Helge HansenInfrastructure support

Faacutebio NevesWeb developer

Marco Fernandes Senior Web developer

Bruno CamposWeb developer

WilmaQA Engineer )

The frontkom family

Fredrikstad | Madeira

Agenda

Why performance Analysis Frontend Server configuration Backend Your inputs

SHOWTIME

We got fast internet connections Powerful computers Shiny large screens

hellipbut wait we got mobilehellipand bad mobile connectionshellipand emerging markets which are mobile only

Why performance now

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 4: Drupalcamp performance

Per Andreacute RoslashnsenCIOChief Innovation Officer

Fredrik PausCOOProject Manager

Thor Andreacute GretlandSupport amp Training

Geir GullandCEO Web strategist

Frank GjertsenWeb Designer

Eacutelio CroacuteWeb Developer

Roberto OrnelasCTO Senior developer

Heacutelder MendesWeb Designer

Elisabeth GullandAccountant

Henrik AkselsenJSMobile UX

Jan-Helge HansenInfrastructure support

Faacutebio NevesWeb developer

Marco Fernandes Senior Web developer

Bruno CamposWeb developer

WilmaQA Engineer )

The frontkom family

Fredrikstad | Madeira

Agenda

Why performance Analysis Frontend Server configuration Backend Your inputs

SHOWTIME

We got fast internet connections Powerful computers Shiny large screens

hellipbut wait we got mobilehellipand bad mobile connectionshellipand emerging markets which are mobile only

Why performance now

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 5: Drupalcamp performance

Fredrikstad | Madeira

Agenda

Why performance Analysis Frontend Server configuration Backend Your inputs

SHOWTIME

We got fast internet connections Powerful computers Shiny large screens

hellipbut wait we got mobilehellipand bad mobile connectionshellipand emerging markets which are mobile only

Why performance now

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 6: Drupalcamp performance

Agenda

Why performance Analysis Frontend Server configuration Backend Your inputs

SHOWTIME

We got fast internet connections Powerful computers Shiny large screens

hellipbut wait we got mobilehellipand bad mobile connectionshellipand emerging markets which are mobile only

Why performance now

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 7: Drupalcamp performance

SHOWTIME

We got fast internet connections Powerful computers Shiny large screens

hellipbut wait we got mobilehellipand bad mobile connectionshellipand emerging markets which are mobile only

Why performance now

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 8: Drupalcamp performance

We got fast internet connections Powerful computers Shiny large screens

hellipbut wait we got mobilehellipand bad mobile connectionshellipand emerging markets which are mobile only

Why performance now

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 9: Drupalcamp performance

Today the average page is 15MB Expect to increase by 21 the next year

Oakley released their new site 80MB

Web pages are getting FAT

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 10: Drupalcamp performance

When to start

We need our clients interest in performance Show visually how a page loads Make a performance budget Plan performance from the beginning

Post-optimization is the root of all evil Lack of performance = Lack of planning Bad performance is bad business

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 11: Drupalcamp performance

We need to analyze this

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 12: Drupalcamp performance

ldquoYeah itrsquos slow but itrsquos probably just [insert wild speculation here]rdquo

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 13: Drupalcamp performance

Hold your assumptions

A lot of the time your assumption will be wrong and cause a lot of wasted effort

Let the data guide the optimizing process Use the 8020 rule =gt find low hanging fruit

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 14: Drupalcamp performance

Tools

Web developer tools in your browsers PageSpeed (Google) Yslow (Yahoo) Quicksprout

httpwwwquicksproutcom WebPageTest

httpwwwwebpagetestorg

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 15: Drupalcamp performance

Chrome Dev Tools

FrontendIntroduction to dev toolshttpbitlydiscover-devtools

ldquoThe Breakpointrdquo Paul Irish Addy Osmani

Indepth analysis

XHProf (Backend)

Find out which functions that are using memory and processor time

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 16: Drupalcamp performance

Mobile first

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 17: Drupalcamp performance

Start small Add style and content as you get more space without limiting the user experiencehttpbradfrostwebcomdemomobile-first

Build systems instead of individual pages Write reusable code

Mobile first

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 18: Drupalcamp performance

Download as few MB as possible Reduce requested files Images css js Concatenate and minify css and js Make sprites

Compass does this in a smart wayhellip Or use icon fonts

httpiconmoonio or even better httpfontasticme

Mobile first

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 19: Drupalcamp performance

HTML

Take control over your markup Customize markup in your tplphp Find design patterns and add classes to

similar elements In views it can be customized directly on

other output use templatephp

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 20: Drupalcamp performance

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 blockgtltsectiongt

ltsection class=panel-pane pane-views-panes pane-commons-activity-streams-activity-panel-pane-1 blockgtltsectiongt

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 21: Drupalcamp performance

function theme_preprocess_panels_pane(amp$vars)

switch ($vars[pane]-gtpid)

case 14

$vars[classes_array][] = box-default

break

case 8

$vars[classes_array] = array(box-default)

break

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 22: Drupalcamp performance

ltsection class=panel-pane pane-views-panes pane-commons-featured-panel-pane-1 block box-defaultgt ltsectiongt

ltsection class=box-defaultgt ltsectiongt

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 23: Drupalcamp performance

Useful gh-repohttpbitlytemplate-php

by Jesper Woslashldiche Rahkonen

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 24: Drupalcamp performance

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 25: Drupalcamp performance

ltdiv class=field field-name-field-test field-type-text field-label-abovegt

ltdiv class=field-labelgtFoobar fieldampnbspltdivgt

ltdiv class=field-itemsgt

ltdiv class=field-item evengtDrupal default fields markupltdivgt

ltdivgt

ltdivgt

Default fields markup

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 26: Drupalcamp performance

lth3 class=field-labelgtFoobar fieldlth3gt

ltdiv class=field-foobargtLeaner markup means better front-end performanceltdivgt

After fences config

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 27: Drupalcamp performance

Modules Clean Markup - Blocks Panel panes Panel regions

Panel layoutshttpsdrupalorgprojectclean_markup

Fences - clean fields markup globalyhttpsdrupalorgprojectfences

Clean markup

Themes Mothership

httpsdrupalorgprojectmothership Aurora

httpsdrupalorgprojectaurora

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 28: Drupalcamp performance

Write as little as possible Use classes instad of tags

ul li a nav-main nav-item httpbitlyquick-selectors

Css can get out of control and hard to manage when a page scales

CSS

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 29: Drupalcamp performance

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 30: Drupalcamp performance

SMACSS A must read for all

working with css Part of the book is

available online for freehttpsmacsscom

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 31: Drupalcamp performance

by Brad Frost

httppattern-labinfo

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 32: Drupalcamp performance

LESS Stylus Sass

Compass - Sass mixins library and much more Breakpoint - Really Simple Media Queries with Sass Toolkit - swiss army knife for PE and RWD Singularity - Grids without limits

Preprocess that CSS

WARNINGAlways check your output

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 33: Drupalcamp performance

btn-default

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

extend btn-default

background-color dodgerblue

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 34: Drupalcamp performance

btn-default btn-cta

text-align center

display inline-block

background-color gray

padding 5px 10px

color white

btn-cta

background-color dodgerblue

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 35: Drupalcamp performance

Donrsquot load js before css Donrsquot load libraries you donrsquot need and if

possible make custom builds to your needs Eg Modernizr

Try to move most of your js at the bottom of your page just before ltbodygt There is a special Drupal module for this

Avoid unnecessary dom manipulations

Javascript

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 36: Drupalcamp performance

MAGIChttpsdrupalorgprojectmagic

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 37: Drupalcamp performance

var div = documentgetElementById(to-measure) lis = documentgetElementsByTagName(li) i len

for (i = 0 len = lislength i lt len i++) lis[i]stylewidth = divoffsetWidth + px

Avoid calculations in loops

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 38: Drupalcamp performance

Edge side includes Image lazy loading

Improve Perceived performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 39: Drupalcamp performance

Tweak it up

Configuration

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 40: Drupalcamp performance

Hosting

Geography - Closer is better (Sorry New Zealand)

SSD is awesome Quick and good support

(Sorry New Zealand) Consider dedicated Drupal hosting

Fx Pantheon (has great workflow)

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 41: Drupalcamp performance

PHP amp MySQL

PHP version newer is betterInnoDB gt Myisam

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 42: Drupalcamp performance

- Opcode cache- Easy setup huge performance win- See httpsdrupalorgnode1777090 for configuration tips for Drupal- Remember to assign enough memory or the cache will not have any effect

APC

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 43: Drupalcamp performance

Improves editor experience + faster site building

Memcache module not needed just include in settingsphp

Alternative Redis

Memcache(d)

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 44: Drupalcamp performance

the path to the core cache file

include_once(includescacheinc)

the path to the memcache cache file

include_once

(sitesallmodulescontribmemcachememcacheinc)

make MemCacheDrupal the default cache class

$conf[cache_default_class] = MemCacheDrupal

$conf[memcache_servers] = array(12700111211 =gt default)

$conf[memcache_bins] = array(cache =gt default)

$conf[memcache_key_prefix] = mysite

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 45: Drupalcamp performance

First time using memcache

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 46: Drupalcamp performance

VarnishBoost(poor manrsquos Varnish)

Gzip

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 47: Drupalcamp performance

CDN Amazon AWS for static files and images Web Application Streaming

new tech possible ldquoCDN killerrdquo) from InstartLogic

High performance with cloud

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 48: Drupalcamp performance

Drupal

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 49: Drupalcamp performance

Good places to hang out

high performance group on do Contrib modules

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 50: Drupalcamp performance

As few modules as possible Avoid the buffet syndrome

Check which hooks are used hook_init() is more important to watch than

hook_openid_normalization_method_info_alter() Preferred Measure beforeafter install

Dive into xhprof Disable suspected performance hogs

Module strategy

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 51: Drupalcamp performance

Check that page cache is not being disabled drupal_page_is_cacheable(FALSE) $GLOBALS[conf][cache] = 0 $GLOBALS[conf][cache] = CACHE_DISABLED $conf[cache] = FALSE flags module captcha module

(This may have to be necessary but at least know that it is happening)

Module strategy

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 52: Drupalcamp performance

Keep an eye on the dblogs May slow down disk if constantly logging

errors May point to underlying errors Bad Karma Tip Get sent an email on each log error

Watch the Logs

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 53: Drupalcamp performance

Cache

Views Cache PHP blocks breaks cache D7 contrib provides a lot D8 Much more flexible out of the box

pluggable CSS and JavaScript optimization personalize through JavaScript Entity Cache

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 54: Drupalcamp performance

Avoid logic in the theme layer hurts page cache

Avoid heavy processes in the theme layer node_load sql queries

Tip Switch to another theme and do performance tests again

Be kind to the theme layer

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 55: Drupalcamp performance

Views queries

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 56: Drupalcamp performance

Find candidates for optimizing

[mysqld]

log_slow_queries=ApplicationsMAMPlogsmysql_sql_slowlog

long_query_time=05

LOTS OF JOINS

SELECT FROM mother_of_all_huge_tables

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 57: Drupalcamp performance

Keep an eye on

PAGERS DISTINCT COUNT JOINS

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 58: Drupalcamp performance

Battle plan Find JOINS and see if you can do the same within SELECT

Tip use EXPLAIN on views sql

How many evaluations

Optimize Views Queries

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 59: Drupalcamp performance

No JOIN

select nid FROM node

200005 rows in set (008 sec)

Data from astonishdesigncom

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 60: Drupalcamp performance

1 JOIN

select nnid sfield_school_name_format

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

200005 rows in set (109 sec)

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 61: Drupalcamp performance

2 JOINS

select nnid sfield_school_name_format sifield_school_id_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

200005 rows in set (203 sec)

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 62: Drupalcamp performance

3 JOINSselect nnid sfield_school_name_format sifield_school_id_value

spfield_school_phone_value

FROM node n

LEFT JOIN field_data_field_school_name s ON nnid = sentity_id

LEFT JOIN field_data_field_school_id si on nnid = sientity_id

LEFT JOIN field_data_field_school_phone sp on nnid = spentity_id

200005 rows in set (503 sec)

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 63: Drupalcamp performance

Optimize in hook_views_query_alter() and hook_view_query_substitutions()

Consider making views into a module Easier to optimize + easier version control

Optimize Views Queries

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 64: Drupalcamp performance

Defer heavy tasks Push heavy tasks to cron Batch API

Fast 404

Specific use cases

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 65: Drupalcamp performance

Good PHP habits

httpwwwphpbenchcom

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 66: Drupalcamp performance

Performance module

New Relic

Load testing with jMeter (+Blazemeter)

Stats

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 67: Drupalcamp performance

Bring out the big guns

Ditch the theme layer

Example NewsFront

Now itrsquos your turn -)

Page 68: Drupalcamp performance

Now itrsquos your turn -)