Slide 1

Slide 1 text

Scale Out Don’t Scale Up WordCamp Maine (May 2014)

Slide 2

Slide 2 text

Xiao Yu @HypertextRanch [email protected] xyu.io xyu     Code Wrangler — Automattic

Slide 3

Slide 3 text

 

Slide 4

Slide 4 text

 Does It Scale?

Slide 5

Slide 5 text

 18,600,000,000 Page Views

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 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 10

Slide 10 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 11

Slide 11 text

 https://automattic.com/work-with-us/

Slide 12

Slide 12 text

Anatomy of a Request 

Slide 13

Slide 13 text

Anatomy of a Request  TCP/IP

Slide 14

Slide 14 text

Anatomy of a Request  HTTP TCP/IP

Slide 15

Slide 15 text

Anatomy of a Request  HTTP Application TCP/IP

Slide 16

Slide 16 text

Anatomy of a Request  HTTP Application Cache TCP/IP

Slide 17

Slide 17 text

Anatomy of a Request  HTTP Application Cache TCP/IP

Slide 18

Slide 18 text

Anatomy of a Request  HTTP Application Cache Database / Filesystem TCP/IP

Slide 19

Slide 19 text

Anatomy of a Request  HTTP Application Cache Database / Filesystem TCP/IP

Slide 20

Slide 20 text

Anatomy of a Request  HTTP Application Cache Database / Filesystem TCP/IP

Slide 21

Slide 21 text

Anatomy of a Request  HTTP Application Cache Database / Filesystem TCP/IP

Slide 22

Slide 22 text

Anatomy of a Request  HTTP Application Cache Database / Filesystem TCP/IP

Slide 23

Slide 23 text

Anatomy of a Request  Cache Database / Filesystem Application HTTP TCP/IP

Slide 24

Slide 24 text

Anatomy of a Request 

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Time to Scale 

Slide 27

Slide 27 text

Time to Scale  

Slide 28

Slide 28 text

More Requests / Second

Slide 29

Slide 29 text

Ways to Scale Software Hardware Be Faster Do More

Slide 30

Slide 30 text

Ways to Scale Software Hardware Be Faster Optimize Bigger Server Do More Async / Multithread More Servers

Slide 31

Slide 31 text

Ways to Scale Software Hardware Be Faster Optimize Bigger Server Do More Async / Multithread More Servers

Slide 32

Slide 32 text

Ways to Scale Software Hardware Be Faster Optimize Scaling Up Do More Async / Multithread More Servers

Slide 33

Slide 33 text

Ways to Scale Software Hardware Be Faster Optimize Scaling Up Do More Async / Multithread Scaling Out

Slide 34

Slide 34 text

Ways to Scale Software Hardware Be Faster Optimize Scaling Up Do More Async / Multithread Scaling Out

Slide 35

Slide 35 text

Out Not Up 

Slide 36

Slide 36 text

Out Not Up 

Slide 37

Slide 37 text

Out Not Up - Amazon vCPU Memory (GB) Cost / HR t2.micro 1 1 $0.013

Slide 38

Slide 38 text

Out Not Up - Amazon vCPU Memory (GB) Cost / HR t2.micro 1 1 $0.013 c4.8xlarge 36 60 $1.856

Slide 39

Slide 39 text

Out Not Up - Amazon vCPU Memory (GB) Cost / HR t2.micro 1 1 $0.013 c4.8xlarge 36 60 $1.856 Δ 36x 60x 142x

Slide 40

Slide 40 text

Out Not Up - Digital Ocean Smallest Largest Δ CPU Cores 1 20 20x Memory (GB) 0.5 64 128x Cost / Month $5 $640 128x

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Out Not Up - Amazon t2.micro c4.8xlarge Δ vCPU 1 36 36x Memory (GB) 1 60 60x Cost / HR $0.013 $1.856 142x

Slide 43

Slide 43 text

Out Not Up 

Slide 44

Slide 44 text

Out Not Up 

Slide 45

Slide 45 text

Out Not Up 

Slide 46

Slide 46 text

Out Not Up 

Slide 47

Slide 47 text

Decoupling & State Cache Database / Filesystem Application HTTP TCP/IP

Slide 48

Slide 48 text

Decoupling & State  Cache Database / Filesystem Application HTTP TCP/IP Cache Database / Filesystem Application HTTP TCP/IP

Slide 49

Slide 49 text

Decoupling & State State  Stateless
 Application Stateless
 Application

Slide 50

Slide 50 text

Stateless
 Application Stateless
 Application Decoupling & State State 

Slide 51

Slide 51 text

Stateless
 Application Stateless
 Application Stateless
 Application Decoupling & State State 

Slide 52

Slide 52 text

Stateless
 Application Stateless
 Application Stateless
 Application Stateless
 Application Decoupling & State State 

Slide 53

Slide 53 text

Stateless
 Application Stateless
 Application Stateless
 Application Stateless
 Application Decoupling & State State 

Slide 54

Slide 54 text

Stateless
 Application Stateless
 Application Stateless
 Application Decoupling & State State 

Slide 55

Slide 55 text

Decoupling & State Cache Database / Filesystem Application HTTP TCP/IP

Slide 56

Slide 56 text

Decoupling & State Cache Database / Filesystem Application HTTP TCP/IP

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

HTTP Request Headers GET /2015/ HTTP/1.1
 
 Host: maine.wordcamp.org
 Accept: text/html,…,image/webp,*/*;q=0.8
 Accept-Language: en-US,en;q=0.8
 Accept-Encoding: gzip, deflate, sdch
 Cache-Control: max-age=0
 Connection: keep-alive
 User-Agent: Mozilla/5.0…
 Cookie: WordPress_test_cookie=…

Slide 60

Slide 60 text

Decoupling & State Cache Database / Filesystem Application HTTP TCP/IP

Slide 61

Slide 61 text

Decoupling & State Cache Database / Filesystem PHP & WordPress HTTP TCP/IP

Slide 62

Slide 62 text

PHP & WordPress Are Stateless By Default

Slide 63

Slide 63 text

PHP & WordPress Are Stateless By Default PHP & WordPress Are Stateless By Default*

Slide 64

Slide 64 text

Local Changes and Uploads Must Be Shared

Slide 65

Slide 65 text

Local Changes and Uploads Must Be Shared Local Changes and Uploads Must Be Shared

Slide 66

Slide 66 text

You Can Break Statelessness

Slide 67

Slide 67 text

function initSession() {
 if ( !session_id() ) {
 session_start();
 }
 $_SESSION[ 'my_key' ] = 'value';
 }
 
 add_action( 'init', 'initSession', 1 );

Slide 68

Slide 68 text

function initSession() {
 if ( !session_id() ) {
 session_start();
 }
 $_SESSION[ 'my_key' ] = 'value';
 }
 
 add_action( 'init', 'initSession', 1 );

Slide 69

Slide 69 text

Use WordPress CRUD APIs Site Data Post Data User Data Short Term Data APIs *_option() *_post_meta() *_user_option()
 *_user_meta() *_transient()

Slide 70

Slide 70 text

Use WordPress CRUD APIs Site Data Post Data User Data Short Term Data APIs *_option() *_post_meta() *_user_option()
 *_user_meta() *_transient() Multisite *_site_option() *_site_transient()

Slide 71

Slide 71 text

Decoupling & State Cache Database / Filesystem PHP & WordPress HTTP TCP/IP 

Slide 72

Slide 72 text

Slide 73

Slide 73 text

Decoupling & State Cache Database / Filesystem Application HTTP TCP/IP

Slide 74

Slide 74 text

Memcached

Slide 75

Slide 75 text

Decoupling & State Cache Database / Filesystem Application HTTP TCP/IP

Slide 76

Slide 76 text

HyperDB

Slide 77

Slide 77 text

Decoupling & State Cache Database / Filesystem Application HTTP TCP/IP

Slide 78

Slide 78 text

Cache Database / Filesystem Application HTTP TCP/IP 

Slide 79

Slide 79 text

Cache Database / Filesystem Application HTTP TCP/IP 

Slide 80

Slide 80 text

Cache Database / Filesystem Application HTTP TCP/IP 

Slide 81

Slide 81 text

Optimize & Scale Each Layer Individually

Slide 82

Slide 82 text

– Ron Swanson “Never half-ass two things.
 Whole-ass one thing.”

Slide 83

Slide 83 text

Optimizations Cache Database / Filesystem Application HTTP TCP/IP

Slide 84

Slide 84 text

Optimizations

Slide 85

Slide 85 text

Optimizations Cache Database / Filesystem Application HTTP TCP/IP

Slide 86

Slide 86 text

Optimizations Photon
 WordPress.com Stats Infinite Scroll Jetpack Comments

Slide 87

Slide 87 text

Optimizations Cache Database / Filesystem Application HTTP TCP/IP

Slide 88

Slide 88 text

Optimizations Related Posts
 Publicize Subscriptions Enhanced Distribution

Slide 89

Slide 89 text

Optimizations Cache Database / Filesystem Application HTTP TCP/IP

Slide 90

Slide 90 text

Decouple, Optimize, and Scale Out

Slide 91

Slide 91 text

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