Slide 1

Slide 1 text

@HypertextRanch  [email protected]  xyu.io  xyu  Scaling WordPress Queries With Elasticsearch Xiao Yu / Automattic

Slide 2

Slide 2 text

 

Slide 3

Slide 3 text

 18,600,000,000 Page Views

Slide 4

Slide 4 text

 18,600,000,000
 409,000,000 Page Views
 Unique Visitors

Slide 5

Slide 5 text

 18,600,000,000
 409,000,000 56,000,000 Page Views
 Unique Visitors
 New Posts

Slide 6

Slide 6 text

 18,600,000,000
 409,000,000 56,000,000
 68,000,000 Page Views
 Unique Visitors
 New Posts
 New Comments

Slide 7

Slide 7 text

 18,600,000,000
 409,000,000 56,000,000
 68,000,000 5,000 Page Views
 Unique Visitors
 New Posts
 New Comments
 Deploys

Slide 8

Slide 8 text

 18,600,000,000
 409,000,000 56,000,000
 68,000,000 5,000
 1 Page Views
 Unique Visitors
 New Posts
 New Comments
 Deploys
 WordPress Multisite

Slide 9

Slide 9 text

Slide 10

Slide 10 text

MySQL server has gone away

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

–Nick Daugherty, WordPress VIP “Elasticsearch can represent a
 >200x improvement for queries
 against cold caches.”

Slide 13

Slide 13 text

new WP_Query( array( 'tax_query' => array( array( 'taxonomy' => 'beer_style', 'field' => 'slug', 'terms' => array( 'ipa', 'pale' ), ) ) ) );

Slide 14

Slide 14 text

SELECT wp_term_taxonomy.term_id FROM wp_term_taxonomy INNER JOIN wp_terms USING ( term_id ) WHERE taxonomy = 'beer_style' AND wp_terms.slug IN ( 'ipa', 'pale' )

Slide 15

Slide 15 text

SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE taxonomy = 'beer_style' AND term_id IN ( 2, 3 )

Slide 16

Slide 16 text

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) WHERE 1=1 AND wp_term_relationships.term_taxonomy_id IN ( 5, 7 ) AND wp_posts.post_type = 'post' AND … GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 25

Slide 17

Slide 17 text

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) WHERE 1=1 AND wp_term_relationships.term_taxonomy_id IN ( 5, 7 ) AND wp_posts.post_type = 'post' AND … GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 25 SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships wp_posts.ID = wp_term_relationships.object_id ) WHERE 1=1 wp_term_relationships.term_taxonomy_id wp_posts.post_type = … GROUP BY wp_posts.ID ORDER BY wp_posts.post_date LIMIT 0, 25

Slide 18

Slide 18 text

SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE wp_postmeta.meta_key = 'hops' AND wp_postmeta.meta_value IN ( 'Amarillo', 'Calypso' )

Slide 19

Slide 19 text

wp_postmeta.meta_value IN ( 'Amarillo', 'Calypso' ) SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta wp_posts.ID = wp_postmeta.post_id WHERE wp_postmeta.meta_key = wp_postmeta.meta_value

Slide 20

Slide 20 text

Elasticsearch Optimizes for Search not Indexing

Slide 21

Slide 21 text

Elasticsearch is Near Realtime

Slide 22

Slide 22 text

Elasticsearch is Denormalized

Slide 23

Slide 23 text

Elasticsearch uses Inverted Indices

Slide 24

Slide 24 text

Elasticsearch uses Bitsets

Slide 25

Slide 25 text

Elasticsearch Optimized for Searching

Slide 26

Slide 26 text

WP_Query() is an API

Slide 27

Slide 27 text

new WP_Query( array( 'tax_query' => array( array( 'taxonomy' => 'beer_style', 'field' => 'slug', 'terms' => array( 'ipa', 'pale' ), ) ) ) );

Slide 28

Slide 28 text

POST /es-index/post/_search { "query": { "filtered": { "filter": { "bool": { "must": [ { "terms": { "taxonomy.beer_style.slug": [ "ipa", "pale" ] } } ] } } } } }

Slide 29

Slide 29 text

https://github.com/alleyinteractive/es-wp-query

Slide 30

Slide 30 text

@HypertextRanch  [email protected]  xyu.io  xyu  Thanks!