Scaling Drupal: Not IF... HOW

Post on 06-May-2015

4.038 views 0 download

description

A brief overview of how to plan for, discover, and treat performance problem areas in Drupal.

Transcript of Scaling Drupal: Not IF... HOW

TreeHouseAgency.com!

Who?�

Thomas Wysocki!Lead Architect!Thomas@treehouseagency.com !

Steven Merrill!Sr. Developer!Steven@treehouseagency.com !

What we're doing today�   Identify scaling issues!

  Introduce an optimization process!

  Look at useful testing and monitoring tools!

Does Drupal Scale?�

When is scaling a concern?�   When there are a lot of:!

  Pageviews!

  Authenticated users!

What if a site doesn't scale?�

Crash!!

Analyze slow

queries!

Analyze slow

pages!

Optimize queries!

Additional!Caching!

Enable slow

query logging!

Test Plan!

Load Testing!

Site Live?!

Additional Techniques!

Front-end Optimization!

Ongoing Monitoring!

Enable Slow Query Log�

•  Ensure you have a my.cnf active!

•  Enable the logging of slow queries inside my.cnf  !

Enable Slow Query Log�

   !

Load testing - why?�   Simulate traffic before your

site hits the real world!

  Populate the site with data automatically!

Load testing - how?�   Utilize load testing software or

services!

  HP Load Runner!

  OpenLoad!

  jMeter !

Load testing - differences?�   Cost!

  Complexity!

  Hardware requirements!

  Types of testing available!

Load Testing - jMeter�

  Note: I have a swf video for now but not sure how to embed that here.   See attachment via email.!

Load Testing - jMeter - Execute�

   !

   !

Reviewing slow query logs�

1.  Check if any files were output to you slow log file.!

2.  Generate a summary of the log file using mysqldumpslow!

Reviewing slow query logs�

   !

Slow Query Logs�•  Typical Problems: !   Poor Indexing resulting in Table

scans!

  Locking!

  large result sets !

  Slow, complicated queries!

Slow Query Log�

  For example:!

Query Optimization�   Things to keep in mind!

  keep it simple!

  know your data!

  be consistent and plan ahead !

Analyze Page execution time�

  screenshot!

Test with the devel module�

  features, screenshot, screencast?!

Implement caching�•  Types of cache !

  Caching Engines!

  Drupal Configurable cache!

  Programmatic caching!

Implement caching�•  Types of caching

engines:!   Standard Drupal Cache!

  APC - standard drupal cache + memory?!

  Memcache!

  Static page cache / Boost !

Standard Drupal Cache�•  positive !   provides caching out of the

box!

•  negative !

  relies upon the database for storage, which results in a lot of reads/writes which can result in table or row locks, etc.!

APC�•  positive !

  much faster performance than memcached !

•  negative !   not networkable, so not suited

to multiple webheads!

Memcache�•  positive !   standard drupal cache +

memory + multiple servers!

•  negative !

  limited control over when and how things disappear from cache!

Static Page Cache/Boost�•  positive!

  drupal flexibility + performance of static files!

•  negative !

  generally works only with anonymous users!

Implement caching�•  Types of configurable

cache: !   Page cache!

  Block Cache!

Page Cache�•  positive !   allows full pages to be

cached, and thus we can serve many more page views on a single server !

•  negative !

  only works for anonymous users!

Block Cache�•  positive !   configurable to work with

anonymous users, as well as logged in users!

  can be page specific, user specific, both or site wide and set to expire at specified intervals!

•  negative !

  hard to control the expiration of data outside of the specified intervals!

Implement caching�•  Types of programmatic

cache: !

  Static variable cache!

  Programmatic data cache!

Static Variable Cache�• positive !  eliminates often duplicate rendered objects!

 core already uses this in some places so that a second node_load() in a page request doesn't hit the database !• negative !

 Only applicable in the course of a single web request!

Programmatic Data Cache�•  positive !   Expensive items can be cached

for a period of time!

  Easily added into custom modules or custom themes !

•  negative !

  Difficult to know where to do it, and invalidating content becomes complicated!

Ongoing monitoring�•  Tools available!   Cacti!

  MySql Enterprise Manager!

  Gomez!

Ongoing monitoring - Cacti�   Free!!

  Monitors various aspect of your site.  !

  cpu utilization!

  server load!

  memory usage!

  database activity!

  Trend visualization!

  Community add-ons !

   !

Additional measures�   Database Scaling!

  Addition of read-only slave servers!

  InnoDB / MyISM / Memory optimization!

  You must currently patch modules or add slave queries to your own modules!

  Drupal 7 should inherently let us do this !

  Hardware changes!

  Load balancers!

  caching!

  redundancy!

Additional measures�   Front-end techniques!

  Apache tweaks!

  CDN!

Front end Techniques�   Front-end performance matters!!

  If a page takes 0.5s to generate and 7s to render, it will still seem slow!

  Use YSlow! to get a score on how fast your website's front-end is!

  JS Aggregation / Compression!

  Similar to CSS Aggregation !

  Load JS on the bottom!

Front end Techniques�   YSlow! in action!

  before optimizing:!

  212.7K (auth user)!

  Almost 6 seconds!

  Barely earns a ‘D’!

Front end Techniques�   JS Aggregation!

  Same size!

  33% faster!

  Better score!

Front end Techniques�   JS Aggregation!

  Core in D6, Available as contrib in D5!

  JS Minification!   Unsafe in PHP!

  CSS Aggregation!   Available out of the box, extremely useful

in reducing the number of http requests needed for each page.   !

CDN�   Load static assets from several

points around the country or world!

  Eliminates unnecessary load on your web servers!

  Relatively cheap!

  Easy to implement   !

  As cloud storage evolves, CDN integration is becoming commoditized, like SimpleCDN!

Front end Techniques�   All images, css

and js on SimpleCDN!

  Gzip compression!

  Far-future expiry headers!

  Page size 40% of original!

  Load time down 45%!

Apache Techniques�   GZip compression!

  Move .htaccess configurations inside your http.config!

Results�   Far-Future

Expiry Headers!

  Gzipping!

  Updated ShareThis!

  212.7k to 99.96k!

  5.7s to 1.7s!

  D to A!!

Key takeaways�   Follow a logical, deliberate

process!

  Leverage the tools available to you!

  Use a multi-faceted approach  !

  Test, test, test!!