Caching, Scaling, and What I've Learned from WordPress.com VIP
Upcoming SlideShare
Loading in...5
×
 

Caching, Scaling, and What I've Learned from WordPress.com VIP

on

  • 3,879 views

Using what I've learned working on the WordPress.com VIP platform, this presentation discusses caching techniques applicable to WordPress installations of almost any size. ...

Using what I've learned working on the WordPress.com VIP platform, this presentation discusses caching techniques applicable to WordPress installations of almost any size.

Presented November 28, 2011 at the Boston WordPress Meetup.

Statistics

Views

Total Views
3,879
Slideshare-icon Views on SlideShare
2,062
Embed Views
1,817

Actions

Likes
1
Downloads
8
Comments
0

20 Embeds 1,817

http://www.thinkoomph.com 638
http://www.ethitter.com 320
http://localhost 312
http://oomph.dev.oomphcloud.com 144
http://ethitterdev.wordpress.com 140
http://oomphinc.zippysites.com 138
http://wpcomdev.ldmh.us 32
http://192.168.0.117 25
http://miguelssandbox.wordpress.com 19
http://www.oomphinc.com 17
http://e15r.net 14
http://oomph.l 6
http://paper.li 5
http://ethitter.com 1
http://ethitter.staging.wpengine.com 1
http://ethitter.wpengine.com 1
http://webcache.googleusercontent.com 1
http://oomphinc.com 1
http://a0.twimg.com 1
http://oomphinc.wpengine.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • To clear, must know both post ID and quantity originally requested.
  • WordPress.com permits caches no larger than 1MB.Array of related posts for site with lots of content can exceed that easily.For VentureBeat, certain ad options are cached into an array so that a default can be provided.
  • Overcomes the limitations of array cache objectDeleting incrementor invalidates any existing caches, which will be pushed out of the object cache over time.
  • Custom loops – InvestorPlace Press CenterData retrieval – CACHE WRAPPERS FOR WORDPRESS FUNCTIONS - term data, including term objects and, especially, term relationships - large blocks of post meta - certain uses of user meta - show VentureBeat/functions/misc.php lines 1432 - 1488Subqueries – excluding taxonomy terms. Will cache data that subquery produces and pass through post__not_in or post__in when possible.Reusable – widgets, menus, common header or footer elements (VentureBeat)
  • Eliminates subquery and its two joinsDropped execution time from roughly 45ms to 30ms.Caching imparts additional performance increase
  • Menu items exist as objects in wp_posts table, organized by the nav_menu taxonomy.Since menu items are in a taxonomy, all taxonomy tables must be joined to posts table to retrieve menu items.If active menu states are unnecessary, the output or wp_nav_menu() can be cached directly.
  • If using custom post types, must create own unique identifierCan add previously-discussed cache incrementor if invalidation is necessary.
  • query_posts() discards a query without using it, then runs a new query. Unnecessarily inefficient.Not intended for creating new loops.
  • First three in context of fragment caching for complex items such as VB menus and footer elementsWeb servers in context of reducing subqueriesWordPress.com infrastructure 1,500+ servers in 3 data centers 25 million sites 2 petabytes of storage 100% using nginxBatcache for page cachingMemcached for object caching Almost all database and caching servers use SSDs.

Caching, Scaling, and What I've Learned from WordPress.com VIP Caching, Scaling, and What I've Learned from WordPress.com VIP Presentation Transcript

  • Caching, Scaling, andWordPress.comVIPErick HitterBoston WordPress Meetup, November 28
  • Why Should You Care AboutAnything I Have to Say?Erick HitterLead WordPress developer with Oomph!@ethitterhttp://www.ethitter.comhttp://www.thinkoomph.comDisclaimer: I started this in Google Docs, then had to switch toPowerPoint, which explains some of the wonky formatting.
  • Caching• Serving static content to a visitor rather than something generated upon request.• Two major types in WordPress context: o Page  Whole page is static and, therefore, could be outdated. o Fragment  Cache pieces of a page rather than the entire page.
  • Fragment Caching BenefitsAllow dynamic and static content to coexist
  • Fragment Caching BenefitsCommon elements can be reused throughout a site
  • Fragment Caching BenefitsReduce calls to APIs
  • WordPress Native Caching APIsTransients Object Cache• Persistent out of the box • Not persistent without a• Stored in wp_options: plugin, such as W3 Total Cache _transient_{key}• WordPress uses for • Storage depends on servers and plugins certain internal functions• set_, get_, and • capabilities Used extensively within delete_transient() WordPress • Cache objects can be grouped • wp_cache_add(), _set, _g et, _delete
  • Fragment Caching Basics: Creating • wp_cache_get() returns a boolean false if the requested cache isnt set or has expired. • Everything that is to be cached must be accessible via a function that returns its results rather than echoing them, otherwise output buffering is needed. • wp_cache_add() will not overwrite an existing, unexpired cache, whereas wp_cache_set() does.
  • Fragment Caching Basics: ClearingThisabove example clears a cache when anything is published or somethingthat is published is modified. The "something" could be a post, page, orcustom post type object.If, instead, the cache should be rebuilt when the same eventoccurs, wp_cache_delete() could be replaced with generate_cached_output().
  • Unpredictable Keys• Object caching doesn’t provide a way to clear all caches in a given group.• Therefore, if the cache key is unpredictable, how can we clear it?• For example, a list of recent posts to be displayed on an individual post, but that excludes the current post.
  • Unpredictable Keys: Recent Posts
  • Unpredictable Keys: Cached Array
  • Unpredictable Keys: Cached ArrayPros Cons• Cache can easily be • Object caching cleared because a single configuration may limit size object with a predictable of individual cache objects. key is set. • Array corruption could• Cache is only rebuilt if invalidate an entire cache specific post ID/quantity object. key is absent from array. • Array can become bloated• Better for cache elements if different quantities are that are reliably small. used simultaneously.• Allows for checking existence of various keys, such as in a loop.
  • Unpredictable Keys: Incrementor
  • Where We Use Fragment Caching• Custom loops• Anytime a lot of data must be retrieved from WordPress and parsed.• Most situations where WP_Query generates a subquery outside of the main query.• Almost anything that is reused across multiple pages.
  • category__not_invspost__not_inSELECT … WHERE 1=1 ANDwp_posts.ID NOT IN (SELECT tr.object_id FROM wp_term_relationshipsAS tr INNER JOIN wp_term_taxonomy AS tt ONtr.term_taxonomy_id = tt.term_taxonomy_id WHEREtt.taxonomy = category AND tt.term_id IN(167) ) …
  • category__not_invspost__not_in
  • category__not_invspost__not_inSELECT … WHERE 1=1 ANDwp_posts.ID NOT IN (SELECT tr.object_id FROM wp_term_relationshipsAS tr INNER JOIN wp_term_taxonomy AS tt ONtr.term_taxonomy_id = tt.term_taxonomy_id WHEREtt.taxonomy = category AND tt.term_id IN(167) ) …SELECT … WHERE 1=1 ANDwp_posts.ID NOT IN (1,2,3,4,5 ) …
  • Menu Caching: No Active States
  • Menu Caching: Active States
  • Menu Caching: Keys & Clearing• get_queried_object_id() returns an integer representing the post ID or term ID.• Front page and custom post type archives return 0.• Menu caches must be cleared when four different actions fire to ensure consistency: o wp_update_nav_menu o wp_update_nav_menu_item o wp_delete_nav_menu o wp_setup_nav_menu_item
  • query_posts() vspre_get_postsquery_posts() pre_get_posts• Function provided to • Action used to modify modify main query. any query.• Runs after main query • Runs before every query has already executed. executes.
  • How Does This Factor Into Our WorkOn WordPress.com VIP?• Page caches only last for five minutes.• No page caching for logged-in users.• Sites that publish with great frequency trigger regular invalidations of homepage and category pages.• Web servers outnumber database servers.• Want to know more about WordPress.com infrastructure? Check out http://goo.gl/lYpJH.
  • Questions?erick@thinkoomph.com@ethitterhttp://www.slideshare.net/ethitter