SlideShare a Scribd company logo
1 of 79
Download to read offline
Drupal Performance
Philip Norton
Blog at #! code (www.hashbangcode.com)
@philipnorton42 on Twitter
Creator of Vlad
Technical Lead at
Philip Norton
Not a sysadmin!
Improving
Performance
Improving
Performance
Performance
Testing
“Performance
enhancements without
benchmarks is little
more than guesswork.”
Probably heard it
at PHPNW...
Setting a benchmark.
“How does the site perform?”
Identifying bottlenecks.
“Where is the site slow?”
Comparing improvements with the benchmark.
“Has that change improved things?”
Gauging the limits of resources.
“If the current traffic doubles will the site fall over?”
1
2
3
4
Performance Testing Goals
Google Chrome
More than a
web browser.
Lots of profiling
tools available.
Measure all kinds of things like raw network speed,
page rendering, and JavaScript performance.
YSlow / ShowSlow
YSlow
YSlow is a Firebug plugin developed by Yahoo! It measures
factors that govern page speed and gives an overall score.
ShowSlow
ShowSlow can be used to store YSlow results and show
difference of scores over time.
Drupal Devel Module
Devel module can be used to render statistics on
the page load.
Shows all SQL queries run and how long they
took to execute.
Queries highlighted in red are slow and should
be addressed.
1
2
3
MySQL Process List
Provides a window on what the MySQL server is
doing, and can pinpoint problems.
> SHOW PROCESSLIST;
Keep an eye out for sleeping or lengthy processes
or processes that transmit lots of data.
Only provides a snapshot of processes.
MySQL Slow Query Log
Often overlooked but provides a valuable
information on queries that are slowing things down.
Set a minimum execution time for queries to be
entered into log.
Use EXPLAIN to figure out why queries are slow.
MySQL Slow Query Log
Add the following to my.cnf:
slow-query-log = 1
slow-query-log-file = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
Use mysqldumpslow to analyse the logs.
Xdebug Profiler
Part of the Xdebug tool.
Shows everything that happened during a page
request.
Use tools like KCachegrind and Webgrind to
view the information and identify bottlenecks.
Very resource heavy so run when needed (never
in production!).
1
2
3
4
XHProf
Generates profiling data for PHP.
Performant enough to run on production
environment.
Can profile 1 request in 100 or 1000 to get a
window on performance.
Use XH Gui to view XHProf results and compare
results over time.
1
2
3
4
Siege / JMeter / Loader.io
Benchmark a site by throwing traffic at it.
Find out how much traffic you can send before
you start getting errors.
Siege and JMeter are a local tools so all traffic
comes from one place.
Loader.io is a distributed service.
1
2
3
4
New Relic
Fully featured performance statistics package
for front and back end monitoring.
Has knowledge of Drupal and can identify slow
modules/views/hooks.
Lots of information available and shows
changes over time.
Paid service and can be a little expensive.
1
2
3
4
Improving Performance
There is no magic bullet!
Speed improvements are made through multiple
improvements and usually have diminishing returns.
Drupal Caching
Too obvious? Cache all the things!
Turn on anonymous page caching.
Use Block Cache Alter module to enable/force block
level caches.
https://www.drupal.org/project/blockcache_alter
1
2
3
Drupal Caching
Turn on Views query and render caching.
Use Entity Cache module to cache entities.
https://www.drupal.org/project/entitycache
1
2
Boost Module
Creates a static cache of page content.
Will also gzip content, including HTML, CSS,
JavaScript, XML.
https://www.drupal.org/project/boost
1
2
CSS / JavaScript Aggregation
Combines CSS and JavaScript files.
Less files being downloaded means:
- Less strain on the server.
- Quicker rendering times for users.
Drupal also removes comments from files which
makes them smaller.
1
2
3
Advanced CSS / JS Aggregation
Easy to install module.
Further reduces JS/CSS footprint by minifying and
compressing the files.
Not a substitute for slow JavaScript code.
https://www.drupal.org/project/advagg
1
2
3
Turn off database Logging
Drupal tends to log a lot of user activity.
PHP warnings and notices can bring a site down
if this module is active.
(You should really be removing these errors
where possible.)
Use syslog to log any errors to file based logs.
1
2
3
Statistics
Writes to the database on every page load.
Use an analytics package instead.
PHP Input Filter
Bypasses most caches. No. Just no.
1
2
Other Bad Modules
Custom Code
Where problems mostly stem from?
Cache where possible.
Try to avoid potentially heavy Drupal hooks like hook_init()
and hook_boot().
Profile and experiment, especially with lots of data. e.g. Test
with 5,000 or 50,000 nodes instead of 5.
1
2
3
Queues
Doing more than one thing in a
page request?
Stick that in a queue and process it later!
Built into Drupal 7, easily extendable.
Should form a key part of any batch process or API
service you implement.
1
2
3
PHP Micro Optimisations
Single quotes '' vs double quotes "".
Printing stuff using echo vs print.
Pre increment (++$i) vs post increment ($i++).
Creating arrays from strings using explode() vs
preg_split().
Micro optimizations are
basically pointless*
*unless you are Facebook.
PHP Micro Optimisations
Performance analysis and benchmarking should
feed into any code modifications.
Don’t optimise code this way unless you have
evidence that you need to.
Don’t sacrifice code maintainability to increase
site speed by 0.00001%.
1
2
3
Drupal Fields
Don’t overuse fields.
node_load() and user_load() will pull in all field
data (plus revisions) into memory.
50 fields on a node means 50 delete and 50
insert statements on every update.
Try to use shared fields where possible.
1
2
3
4
Cron
Don’t get your users to run cron.
Always do it via a crontab.
Use Elysia cron module to split the cron up.
Set cache clearing cron runs to hourly.
https://www.drupal.org/project/elysia_cron
1
2
3
PHP 5.5+
New versions of PHP are faster than ever.
Especially with objects.
You should be upgrading to take advantage of this.
Use PHP-FPM for high performance PHP.
1
2
3
4
PHP Opcode Cache
e.g. APC or Zend Cache.
Caches PHP scripts so they don’t have to be
recompiled when run again.
Easy to install and gives a speed increase
of up to 30%.
Make sure your cache size is big enough to
accommodate the number of files!
1
2
3
4
Add indexes to tables. Slow query log will tell you
where indexes are needed.
Add enough memory for MySQL to use (you don’t
want lots of read/writes to disk).
Use a master/slave setup - Drupal will use slave
server for expensive read only queries (eg. search).
MySQL Performance Tweaks
1
2
3
Apache Performance Tweaks
Turn off KeepAlive.
Set your max clients to a sensible value.
- Too high and server crashes when busy.
- Too low and you can’t serve traffic correctly.
Remove any modules that you don’t need.
Turn off AllowOverride and include .htaccess files in
server configuration.
1
2
3
4
Solr Search
Moves search out of your database server.
Much more efficient and has a bunch of nice
features (e.g. facets).
Hard to set up, but services exist to help you.
1
2
3
Memcache / Redis
Store your Drupal cache outside of a database.
Much faster than traditional database servers
(but only for this kind of data).
Can be scaled easily.
1
2
3
Split Site Up
Complex sites can be slow. Breaking them into sub-
sites allows for better experience.
Most users don’t care about the URL, as long as
they get a coherent experience.
Other sites can be hosted elsewhere.
Bakery module provides single sign on.
1
2
3
4
Server Side Caching
i.e. Varnish.
Provides a reverse proxy that caches all page
content.
Repeat requests never hit Drupal, Apache, or
MySQL and are instead served by Varnish.
Huge speed increase for little effort.
1
2
3
4
Load Balancers
Balances the load across multiple web servers.
More complex to setup, but some providers have
good solutions (Rackspace).
Stops Apache being the bottleneck.
Can have some negative effects on Drupal (e.g. file
uploads available on all servers).
1
2
3
4
Content Delivery Network (CDN)
Move the files or even the entire site out of your
hosting environment.
Pull vs push CDN.
CDN content nodes closer to users mean less
distance to travel for request/response.
Make sure you allow authentication traffic through.
1
2
3
4
Throw money at it!
Throw money at it!
Buying monster servers does not necessarily
mean performance improvements.
Can sometimes solve the wrong problem.
If you plaster over cracks, the cracks will still be
there.
“We’ve spent all this money on servers and the
site is still slow.” - An annoyed client
1
2
3
4
To Recap...
Server
PHP 5.5+ with APC
Optimised MySQL
Optimised Apache
Memcache/Redis
Solr
1
2
3
4
5
Drupal
Cache all the things
JS/CSS aggregation
Split complex sites up
Disable expensive
modules
1
2
3
4
External
Varnish
Load balancers
CDN
1
2
3
Essentially...
“Making a Drupal site fast
is mostly about removing
Drupal from the page
request.”
Philip Norton
Failing Gracefully
If at first you don’t succeed, fail!
Drupal Log Levels
Set a level that won’t print error logs to screen.
Maintenance theme
Config item in Drupal’s settings.php file.
Create a nice looking error page that fits in with
site theme.
Link out to social media channels.
Prevent Drupal from printing SQL error messages.
1
2
3
4
Varnish error page
If your web server doesn’t respond then Varnish
can be made to issue an error page.
Or even redirect traffic to another (static) site.
1
2
Static pages
Don’t be afraid to present users with a static page.
“We’re busy, please come back later” is better than
an error page.
With load balanced solutions you can give a
percentage of your users a static page and serve
the rest correctly.
1
2
3
Case Study
A quick case study about dealing with
peak traffic on awards nights
BAFTA: Peak traffic
High levels of traffic on major awards nights.
1,400% increase from normal traffic levels.
Needed a scalable hosting solution that could be
ramped up on selected evenings.
Rackspace cloud chosen as the hosting platform.
1
2
3
4
BAFTA: Peak traffic
Film and TV awards
Games Awards
Nominees Announced
Children’s Awards
1
2
4
BAFTA: Peak traffic
Sites are hosted on a number of web nodes.
Rackspace Load Balancer provides unified front end.
Each web node consists of a Varnish/Apache setup.
1
2
3
BAFTA: Peak traffic
In the run-up to awards night new nodes are
provisioned and added to the load balancer.
Caches on each web node are warmed and site is
load tested using loader.io service.
After awards night the nodes are scaled down to
normal service.
1
2
3
BAFTA: Peak traffic
Rackspace Load
Balancer
Web
Nodes
SolrNFSMySQL
Master/Slave
BAFTA: Peak traffic
Varnish
Apache
Load BalancerEach web node setup as
a Varnish/Apache pair.
Varnish configured to
produce nice error page
if Apache not available.
1
2
BAFTA: Peak traffic
Contingency plans put in place just in case things
went wrong.
Error page templates put in place for:
- Drupal
- Varnish
- Rackspace load balancer
Secure login module ready to disable member access
to reduce load on database server.
1
2
3
BAFTA: Peak traffic
Team Access on call during the weekend in case of
issues.
Rackspace also had a dedicated technician on hand.
Monitoring of servers during awards ceremony in
order to adapt to any problems.
1
2
3
BAFTA: Peak traffic
Cloudflare chosen as a CDN.
Caches content externally for anonymous traffic.
Cloudflare module used to clear external caches from
within Drupal.
>90% of all traffic served through Cloudflare.
1
2
3
4
BAFTA: Peak traffic
BAFTA: Results
No downtime.
Cloudflare served most of the traffic.
Site stayed responsive throughout the peak traffic
levels.
Client happy.
1
2
3
4
BAFTA: Peak traffic
Fin.

More Related Content

What's hot

Stress Test Drupal on Amazon EC2 vs. RackSpace cloud
Stress Test Drupal on Amazon EC2 vs. RackSpace cloudStress Test Drupal on Amazon EC2 vs. RackSpace cloud
Stress Test Drupal on Amazon EC2 vs. RackSpace cloudAndy Kucharski
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal PerformancesVladimir Ilic
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedAndy Kucharski
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackMatt Ray
 
Effectively Deploying MongoDB on AEM
Effectively Deploying MongoDB on AEMEffectively Deploying MongoDB on AEM
Effectively Deploying MongoDB on AEMNorberto Leite
 
DrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceDrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceAshok Modi
 
DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingAshok Modi
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack OptimizationDave Ross
 
Integrated Cache on Netscaler
Integrated Cache on NetscalerIntegrated Cache on Netscaler
Integrated Cache on NetscalerMark Hillick
 
101 ways to configure kafka - badly
101 ways to configure kafka - badly101 ways to configure kafka - badly
101 ways to configure kafka - badlyHenning Spjelkavik
 
High-Performance Magento in the Cloud
High-Performance Magento in the CloudHigh-Performance Magento in the Cloud
High-Performance Magento in the CloudAOE
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)WordCamp Cape Town
 
Simplify your integrations with Apache Camel
Simplify your integrations with Apache CamelSimplify your integrations with Apache Camel
Simplify your integrations with Apache CamelKenneth Peeples
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Archroyans
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh thingsMarcus Deglos
 

What's hot (20)

Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Stress Test Drupal on Amazon EC2 vs. RackSpace cloud
Stress Test Drupal on Amazon EC2 vs. RackSpace cloudStress Test Drupal on Amazon EC2 vs. RackSpace cloud
Stress Test Drupal on Amazon EC2 vs. RackSpace cloud
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speed
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStack
 
Effectively Deploying MongoDB on AEM
Effectively Deploying MongoDB on AEMEffectively Deploying MongoDB on AEM
Effectively Deploying MongoDB on AEM
 
23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress
 
DrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceDrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performance
 
DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizing
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack Optimization
 
Integrated Cache on Netscaler
Integrated Cache on NetscalerIntegrated Cache on Netscaler
Integrated Cache on Netscaler
 
101 ways to configure kafka - badly
101 ways to configure kafka - badly101 ways to configure kafka - badly
101 ways to configure kafka - badly
 
Building Web APIs that Scale
Building Web APIs that ScaleBuilding Web APIs that Scale
Building Web APIs that Scale
 
Zendcon zray
Zendcon zrayZendcon zray
Zendcon zray
 
High-Performance Magento in the Cloud
High-Performance Magento in the CloudHigh-Performance Magento in the Cloud
High-Performance Magento in the Cloud
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)
 
Scaling PHP web apps
Scaling PHP web appsScaling PHP web apps
Scaling PHP web apps
 
Simplify your integrations with Apache Camel
Simplify your integrations with Apache CamelSimplify your integrations with Apache Camel
Simplify your integrations with Apache Camel
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Arch
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh things
 

Viewers also liked

Making The Drupal Pill Easier To Swallow
Making The Drupal Pill Easier To SwallowMaking The Drupal Pill Easier To Swallow
Making The Drupal Pill Easier To SwallowPhilip Norton
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master BuilderPhilip Norton
 
Acquia Drupal Certification
Acquia Drupal CertificationAcquia Drupal Certification
Acquia Drupal CertificationPhilip Norton
 
Getting Started With Jenkins And Drupal
Getting Started With Jenkins And DrupalGetting Started With Jenkins And Drupal
Getting Started With Jenkins And DrupalPhilip Norton
 
Drupal 8 Configuration Management
Drupal 8 Configuration ManagementDrupal 8 Configuration Management
Drupal 8 Configuration ManagementPhilip Norton
 

Viewers also liked (6)

Making The Drupal Pill Easier To Swallow
Making The Drupal Pill Easier To SwallowMaking The Drupal Pill Easier To Swallow
Making The Drupal Pill Easier To Swallow
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
 
Drupal theming
Drupal themingDrupal theming
Drupal theming
 
Acquia Drupal Certification
Acquia Drupal CertificationAcquia Drupal Certification
Acquia Drupal Certification
 
Getting Started With Jenkins And Drupal
Getting Started With Jenkins And DrupalGetting Started With Jenkins And Drupal
Getting Started With Jenkins And Drupal
 
Drupal 8 Configuration Management
Drupal 8 Configuration ManagementDrupal 8 Configuration Management
Drupal 8 Configuration Management
 

Similar to Drupal Performance : DrupalCamp North

Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practiceswebuploader
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101Angus Li
 
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Bhupesh Bansal
 
Hadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop User Group
 
Magento performancenbs
Magento performancenbsMagento performancenbs
Magento performancenbsvarien
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and ScalabilityMediacurrent
 
Performance Optimization in Drupal 8
Performance Optimization in Drupal 8Performance Optimization in Drupal 8
Performance Optimization in Drupal 8valuebound
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And ScalabilityJason Ragsdale
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedPromet Source
 
Drupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityDrupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityAshok Modi
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014Ryusuke Kajiyama
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysqlliufabin 66688
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on SteroidsSiteGround.com
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...John McCaffrey
 
Windy cityrails performance_tuning
Windy cityrails performance_tuningWindy cityrails performance_tuning
Windy cityrails performance_tuningJohn McCaffrey
 
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010Yahoo Developer Network
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015Christopher Curtin
 

Similar to Drupal Performance : DrupalCamp North (20)

Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practices
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101
 
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
 
Hadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedIn
 
Magento performancenbs
Magento performancenbsMagento performancenbs
Magento performancenbs
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and Scalability
 
Performance Optimization in Drupal 8
Performance Optimization in Drupal 8Performance Optimization in Drupal 8
Performance Optimization in Drupal 8
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And Scalability
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speed
 
Drupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityDrupal Backend Performance and Scalability
Drupal Backend Performance and Scalability
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysql
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
 
Windy cityrails performance_tuning
Windy cityrails performance_tuningWindy cityrails performance_tuning
Windy cityrails performance_tuning
 
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015
 

More from Philip Norton

Getting Into Drupal 8 Configuration
Getting Into Drupal 8 ConfigurationGetting Into Drupal 8 Configuration
Getting Into Drupal 8 ConfigurationPhilip Norton
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionPhilip Norton
 
Webform and Drupal 8
Webform and Drupal 8Webform and Drupal 8
Webform and Drupal 8Philip Norton
 

More from Philip Norton (7)

ReactPHP
ReactPHPReactPHP
ReactPHP
 
Getting Into Drupal 8 Configuration
Getting Into Drupal 8 ConfigurationGetting Into Drupal 8 Configuration
Getting Into Drupal 8 Configuration
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
 
Drupal 8 Services
Drupal 8 ServicesDrupal 8 Services
Drupal 8 Services
 
Webform and Drupal 8
Webform and Drupal 8Webform and Drupal 8
Webform and Drupal 8
 
Drush
DrushDrush
Drush
 
Drupal 7 Queues
Drupal 7 QueuesDrupal 7 Queues
Drupal 7 Queues
 

Recently uploaded

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Drupal Performance : DrupalCamp North

  • 2. Blog at #! code (www.hashbangcode.com) @philipnorton42 on Twitter Creator of Vlad Technical Lead at Philip Norton
  • 7. “Performance enhancements without benchmarks is little more than guesswork.” Probably heard it at PHPNW...
  • 8. Setting a benchmark. “How does the site perform?” Identifying bottlenecks. “Where is the site slow?” Comparing improvements with the benchmark. “Has that change improved things?” Gauging the limits of resources. “If the current traffic doubles will the site fall over?” 1 2 3 4 Performance Testing Goals
  • 9. Google Chrome More than a web browser. Lots of profiling tools available. Measure all kinds of things like raw network speed, page rendering, and JavaScript performance.
  • 10.
  • 11.
  • 12.
  • 13. YSlow / ShowSlow YSlow YSlow is a Firebug plugin developed by Yahoo! It measures factors that govern page speed and gives an overall score. ShowSlow ShowSlow can be used to store YSlow results and show difference of scores over time.
  • 14.
  • 15.
  • 16.
  • 17. Drupal Devel Module Devel module can be used to render statistics on the page load. Shows all SQL queries run and how long they took to execute. Queries highlighted in red are slow and should be addressed. 1 2 3
  • 18.
  • 19. MySQL Process List Provides a window on what the MySQL server is doing, and can pinpoint problems. > SHOW PROCESSLIST; Keep an eye out for sleeping or lengthy processes or processes that transmit lots of data. Only provides a snapshot of processes.
  • 20. MySQL Slow Query Log Often overlooked but provides a valuable information on queries that are slowing things down. Set a minimum execution time for queries to be entered into log. Use EXPLAIN to figure out why queries are slow.
  • 21. MySQL Slow Query Log Add the following to my.cnf: slow-query-log = 1 slow-query-log-file = /var/log/mysql/mysql-slow.log long_query_time = 2 log-queries-not-using-indexes Use mysqldumpslow to analyse the logs.
  • 22. Xdebug Profiler Part of the Xdebug tool. Shows everything that happened during a page request. Use tools like KCachegrind and Webgrind to view the information and identify bottlenecks. Very resource heavy so run when needed (never in production!). 1 2 3 4
  • 23. XHProf Generates profiling data for PHP. Performant enough to run on production environment. Can profile 1 request in 100 or 1000 to get a window on performance. Use XH Gui to view XHProf results and compare results over time. 1 2 3 4
  • 24.
  • 25.
  • 26. Siege / JMeter / Loader.io Benchmark a site by throwing traffic at it. Find out how much traffic you can send before you start getting errors. Siege and JMeter are a local tools so all traffic comes from one place. Loader.io is a distributed service. 1 2 3 4
  • 27. New Relic Fully featured performance statistics package for front and back end monitoring. Has knowledge of Drupal and can identify slow modules/views/hooks. Lots of information available and shows changes over time. Paid service and can be a little expensive. 1 2 3 4
  • 28.
  • 30. There is no magic bullet! Speed improvements are made through multiple improvements and usually have diminishing returns.
  • 31. Drupal Caching Too obvious? Cache all the things! Turn on anonymous page caching. Use Block Cache Alter module to enable/force block level caches. https://www.drupal.org/project/blockcache_alter 1 2 3
  • 32. Drupal Caching Turn on Views query and render caching. Use Entity Cache module to cache entities. https://www.drupal.org/project/entitycache 1 2
  • 33. Boost Module Creates a static cache of page content. Will also gzip content, including HTML, CSS, JavaScript, XML. https://www.drupal.org/project/boost 1 2
  • 34. CSS / JavaScript Aggregation Combines CSS and JavaScript files. Less files being downloaded means: - Less strain on the server. - Quicker rendering times for users. Drupal also removes comments from files which makes them smaller. 1 2 3
  • 35. Advanced CSS / JS Aggregation Easy to install module. Further reduces JS/CSS footprint by minifying and compressing the files. Not a substitute for slow JavaScript code. https://www.drupal.org/project/advagg 1 2 3
  • 36. Turn off database Logging Drupal tends to log a lot of user activity. PHP warnings and notices can bring a site down if this module is active. (You should really be removing these errors where possible.) Use syslog to log any errors to file based logs. 1 2 3
  • 37. Statistics Writes to the database on every page load. Use an analytics package instead. PHP Input Filter Bypasses most caches. No. Just no. 1 2 Other Bad Modules
  • 38. Custom Code Where problems mostly stem from? Cache where possible. Try to avoid potentially heavy Drupal hooks like hook_init() and hook_boot(). Profile and experiment, especially with lots of data. e.g. Test with 5,000 or 50,000 nodes instead of 5. 1 2 3
  • 39. Queues Doing more than one thing in a page request? Stick that in a queue and process it later! Built into Drupal 7, easily extendable. Should form a key part of any batch process or API service you implement. 1 2 3
  • 40. PHP Micro Optimisations Single quotes '' vs double quotes "". Printing stuff using echo vs print. Pre increment (++$i) vs post increment ($i++). Creating arrays from strings using explode() vs preg_split().
  • 41. Micro optimizations are basically pointless* *unless you are Facebook.
  • 42. PHP Micro Optimisations Performance analysis and benchmarking should feed into any code modifications. Don’t optimise code this way unless you have evidence that you need to. Don’t sacrifice code maintainability to increase site speed by 0.00001%. 1 2 3
  • 43. Drupal Fields Don’t overuse fields. node_load() and user_load() will pull in all field data (plus revisions) into memory. 50 fields on a node means 50 delete and 50 insert statements on every update. Try to use shared fields where possible. 1 2 3 4
  • 44. Cron Don’t get your users to run cron. Always do it via a crontab. Use Elysia cron module to split the cron up. Set cache clearing cron runs to hourly. https://www.drupal.org/project/elysia_cron 1 2 3
  • 45. PHP 5.5+ New versions of PHP are faster than ever. Especially with objects. You should be upgrading to take advantage of this. Use PHP-FPM for high performance PHP. 1 2 3 4
  • 46. PHP Opcode Cache e.g. APC or Zend Cache. Caches PHP scripts so they don’t have to be recompiled when run again. Easy to install and gives a speed increase of up to 30%. Make sure your cache size is big enough to accommodate the number of files! 1 2 3 4
  • 47.
  • 48. Add indexes to tables. Slow query log will tell you where indexes are needed. Add enough memory for MySQL to use (you don’t want lots of read/writes to disk). Use a master/slave setup - Drupal will use slave server for expensive read only queries (eg. search). MySQL Performance Tweaks 1 2 3
  • 49. Apache Performance Tweaks Turn off KeepAlive. Set your max clients to a sensible value. - Too high and server crashes when busy. - Too low and you can’t serve traffic correctly. Remove any modules that you don’t need. Turn off AllowOverride and include .htaccess files in server configuration. 1 2 3 4
  • 50. Solr Search Moves search out of your database server. Much more efficient and has a bunch of nice features (e.g. facets). Hard to set up, but services exist to help you. 1 2 3
  • 51. Memcache / Redis Store your Drupal cache outside of a database. Much faster than traditional database servers (but only for this kind of data). Can be scaled easily. 1 2 3
  • 52. Split Site Up Complex sites can be slow. Breaking them into sub- sites allows for better experience. Most users don’t care about the URL, as long as they get a coherent experience. Other sites can be hosted elsewhere. Bakery module provides single sign on. 1 2 3 4
  • 53. Server Side Caching i.e. Varnish. Provides a reverse proxy that caches all page content. Repeat requests never hit Drupal, Apache, or MySQL and are instead served by Varnish. Huge speed increase for little effort. 1 2 3 4
  • 54. Load Balancers Balances the load across multiple web servers. More complex to setup, but some providers have good solutions (Rackspace). Stops Apache being the bottleneck. Can have some negative effects on Drupal (e.g. file uploads available on all servers). 1 2 3 4
  • 55. Content Delivery Network (CDN) Move the files or even the entire site out of your hosting environment. Pull vs push CDN. CDN content nodes closer to users mean less distance to travel for request/response. Make sure you allow authentication traffic through. 1 2 3 4
  • 57. Throw money at it! Buying monster servers does not necessarily mean performance improvements. Can sometimes solve the wrong problem. If you plaster over cracks, the cracks will still be there. “We’ve spent all this money on servers and the site is still slow.” - An annoyed client 1 2 3 4
  • 58. To Recap... Server PHP 5.5+ with APC Optimised MySQL Optimised Apache Memcache/Redis Solr 1 2 3 4 5 Drupal Cache all the things JS/CSS aggregation Split complex sites up Disable expensive modules 1 2 3 4 External Varnish Load balancers CDN 1 2 3
  • 60. “Making a Drupal site fast is mostly about removing Drupal from the page request.” Philip Norton
  • 61. Failing Gracefully If at first you don’t succeed, fail!
  • 62. Drupal Log Levels Set a level that won’t print error logs to screen.
  • 63. Maintenance theme Config item in Drupal’s settings.php file. Create a nice looking error page that fits in with site theme. Link out to social media channels. Prevent Drupal from printing SQL error messages. 1 2 3 4
  • 64. Varnish error page If your web server doesn’t respond then Varnish can be made to issue an error page. Or even redirect traffic to another (static) site. 1 2
  • 65. Static pages Don’t be afraid to present users with a static page. “We’re busy, please come back later” is better than an error page. With load balanced solutions you can give a percentage of your users a static page and serve the rest correctly. 1 2 3
  • 66. Case Study A quick case study about dealing with peak traffic on awards nights
  • 67. BAFTA: Peak traffic High levels of traffic on major awards nights. 1,400% increase from normal traffic levels. Needed a scalable hosting solution that could be ramped up on selected evenings. Rackspace cloud chosen as the hosting platform. 1 2 3 4
  • 68. BAFTA: Peak traffic Film and TV awards Games Awards Nominees Announced Children’s Awards 1 2 4
  • 69. BAFTA: Peak traffic Sites are hosted on a number of web nodes. Rackspace Load Balancer provides unified front end. Each web node consists of a Varnish/Apache setup. 1 2 3
  • 70. BAFTA: Peak traffic In the run-up to awards night new nodes are provisioned and added to the load balancer. Caches on each web node are warmed and site is load tested using loader.io service. After awards night the nodes are scaled down to normal service. 1 2 3
  • 71. BAFTA: Peak traffic Rackspace Load Balancer Web Nodes SolrNFSMySQL Master/Slave
  • 72. BAFTA: Peak traffic Varnish Apache Load BalancerEach web node setup as a Varnish/Apache pair. Varnish configured to produce nice error page if Apache not available. 1 2
  • 73. BAFTA: Peak traffic Contingency plans put in place just in case things went wrong. Error page templates put in place for: - Drupal - Varnish - Rackspace load balancer Secure login module ready to disable member access to reduce load on database server. 1 2 3
  • 74. BAFTA: Peak traffic Team Access on call during the weekend in case of issues. Rackspace also had a dedicated technician on hand. Monitoring of servers during awards ceremony in order to adapt to any problems. 1 2 3
  • 75. BAFTA: Peak traffic Cloudflare chosen as a CDN. Caches content externally for anonymous traffic. Cloudflare module used to clear external caches from within Drupal. >90% of all traffic served through Cloudflare. 1 2 3 4
  • 77. BAFTA: Results No downtime. Cloudflare served most of the traffic. Site stayed responsive throughout the peak traffic levels. Client happy. 1 2 3 4
  • 79. Fin.