Scaling Drupal: Not IF... HOW

50

description

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

Transcript of Scaling Drupal: Not IF... HOW

Page 1: Scaling Drupal: Not IF... HOW
Page 2: Scaling Drupal: Not IF... HOW

TreeHouseAgency.com!

Who?�

Page 3: Scaling Drupal: Not IF... HOW

Thomas Wysocki!Lead [email protected] !

Steven Merrill!Sr. [email protected] !

Page 4: Scaling Drupal: Not IF... HOW

What we're doing today�   Identify scaling issues!

  Introduce an optimization process!

  Look at useful testing and monitoring tools!

Page 5: Scaling Drupal: Not IF... HOW

Does Drupal Scale?�

Page 6: Scaling Drupal: Not IF... HOW
Page 7: Scaling Drupal: Not IF... HOW

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

  Pageviews!

  Authenticated users!

Page 8: Scaling Drupal: Not IF... HOW

What if a site doesn't scale?�

Crash!!

Page 9: Scaling Drupal: Not IF... HOW

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!

Page 10: Scaling Drupal: Not IF... HOW

Enable Slow Query Log�

•  Ensure you have a my.cnf active!

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

Page 11: Scaling Drupal: Not IF... HOW

Enable Slow Query Log�

   !

Page 12: Scaling Drupal: Not IF... HOW

Load testing - why?�   Simulate traffic before your

site hits the real world!

  Populate the site with data automatically!

Page 13: Scaling Drupal: Not IF... HOW

Load testing - how?�   Utilize load testing software or

services!

  HP Load Runner!

  OpenLoad!

  jMeter !

Page 14: Scaling Drupal: Not IF... HOW

Load testing - differences?�   Cost!

  Complexity!

  Hardware requirements!

  Types of testing available!

Page 15: Scaling Drupal: Not IF... HOW

Load Testing - jMeter�

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

Page 16: Scaling Drupal: Not IF... HOW

Load Testing - jMeter - Execute�

   !

Page 17: Scaling Drupal: Not IF... HOW

   !

Page 18: Scaling Drupal: Not IF... HOW

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!

Page 19: Scaling Drupal: Not IF... HOW

Reviewing slow query logs�

   !

Page 20: Scaling Drupal: Not IF... HOW

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

scans!

  Locking!

  large result sets !

  Slow, complicated queries!

Page 21: Scaling Drupal: Not IF... HOW

Slow Query Log�

  For example:!

Page 22: Scaling Drupal: Not IF... HOW

Query Optimization�   Things to keep in mind!

  keep it simple!

  know your data!

  be consistent and plan ahead !

Page 23: Scaling Drupal: Not IF... HOW

Analyze Page execution time�

  screenshot!

Page 24: Scaling Drupal: Not IF... HOW

Test with the devel module�

  features, screenshot, screencast?!

Page 25: Scaling Drupal: Not IF... HOW

Implement caching�•  Types of cache !

  Caching Engines!

  Drupal Configurable cache!

  Programmatic caching!

Page 26: Scaling Drupal: Not IF... HOW

Implement caching�•  Types of caching

engines:!   Standard Drupal Cache!

  APC - standard drupal cache + memory?!

  Memcache!

  Static page cache / Boost !

Page 27: Scaling Drupal: Not IF... HOW

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.!

Page 28: Scaling Drupal: Not IF... HOW

APC�•  positive !

  much faster performance than memcached !

•  negative !   not networkable, so not suited

to multiple webheads!

Page 29: Scaling Drupal: Not IF... HOW

Memcache�•  positive !   standard drupal cache +

memory + multiple servers!

•  negative !

  limited control over when and how things disappear from cache!

Page 30: Scaling Drupal: Not IF... HOW

Static Page Cache/Boost�•  positive!

  drupal flexibility + performance of static files!

•  negative !

  generally works only with anonymous users!

Page 31: Scaling Drupal: Not IF... HOW

Implement caching�•  Types of configurable

cache: !   Page cache!

  Block Cache!

Page 32: Scaling Drupal: Not IF... HOW

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!

Page 33: Scaling Drupal: Not IF... HOW

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!

Page 34: Scaling Drupal: Not IF... HOW

Implement caching�•  Types of programmatic

cache: !

  Static variable cache!

  Programmatic data cache!

Page 35: Scaling Drupal: Not IF... HOW

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!

Page 36: Scaling Drupal: Not IF... HOW

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!

Page 37: Scaling Drupal: Not IF... HOW

Ongoing monitoring�•  Tools available!   Cacti!

  MySql Enterprise Manager!

  Gomez!

Page 38: Scaling Drupal: Not IF... HOW

Ongoing monitoring - Cacti�   Free!!

  Monitors various aspect of your site.  !

  cpu utilization!

  server load!

  memory usage!

  database activity!

  Trend visualization!

  Community add-ons !

Page 39: Scaling Drupal: Not IF... HOW

   !

Page 40: Scaling Drupal: Not IF... HOW

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!

Page 41: Scaling Drupal: Not IF... HOW

Additional measures�   Front-end techniques!

  Apache tweaks!

  CDN!

Page 42: Scaling Drupal: Not IF... HOW

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!

Page 43: Scaling Drupal: Not IF... HOW

Front end Techniques�   YSlow! in action!

  before optimizing:!

  212.7K (auth user)!

  Almost 6 seconds!

  Barely earns a ‘D’!

Page 44: Scaling Drupal: Not IF... HOW

Front end Techniques�   JS Aggregation!

  Same size!

  33% faster!

  Better score!

Page 45: Scaling Drupal: Not IF... HOW

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.   !

Page 46: Scaling Drupal: Not IF... HOW

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!

Page 47: Scaling Drupal: Not IF... HOW

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%!

Page 48: Scaling Drupal: Not IF... HOW

Apache Techniques�   GZip compression!

  Move .htaccess configurations inside your http.config!

Page 49: Scaling Drupal: Not IF... HOW

Results�   Far-Future

Expiry Headers!

  Gzipping!

  Updated ShareThis!

  212.7k to 99.96k!

  5.7s to 1.7s!

  D to A!!

Page 50: Scaling Drupal: Not IF... HOW

Key takeaways�   Follow a logical, deliberate

process!

  Leverage the tools available to you!

  Use a multi-faceted approach  !

  Test, test, test!!