Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP World - 2015 - Infinitely Scalable WordPres...

E.T.Cook
November 19, 2015

PHP World - 2015 - Infinitely Scalable WordPress Environments

Many people don't realize that WordPress is primed for horizontal scaling out of the box. We'll take a look at two solutions that allow for quick and easy horizontal scaling of WordPress, Docker and Forge. We'll cover strategies, tactics, configuration patterns, failover, load balancing, session management, uploads sharing, db management, caching, staging environments, and other common pitfalls. We'll also briefly touch upon ancillary and supportive services like aggregated live log tail with Papertrail to assist in troubleshooting and dev. There should be something for non-WP devs, as well.

E.T.Cook

November 19, 2015
Tweet

More Decks by E.T.Cook

Other Decks in Technology

Transcript

  1. EUGENE T. COOK PHP WORLD - NOVEMBER 19 INFINITELY SCALING

    WORDPRESS THE SUBSTANTIVE APPROACH TO WEB SCALE
  2. A BIT ABOUT ME Transactional and Start Up Attorney MBA

    - IT and 
 Operations Management Polymathic Technologist JD - Rule of Law in
 Developing Nations Shameless Plugs
  3. What will we cover? SCALING WORDPRESS 1. DIFFERENT APPROACHES TO

    OPTIMIZATION AND INCREASING SCALABILITY 2. APPLICATION OF EACH 3. CONTEXTUALIZE EACH LAYER IN THE STACK FOR OPTIMIZATION 4. REVIEW SELECT OPTIONS ON HOW TO PRACTICALLY SCALE WORDPRESS
  4. OPTIMIZATION? I THOUGHT THIS WAS A PRESENTATION ABOUT SCALING OPTIMIZATION

    IS THE PROCESS OF IMPROVING THE SCALABILITY OF YOUR APPLICATION
  5. Front-End Cacheing SUPERFICIAL OPTIMIZATION • MOST COMMON FORM OF OPTIMIZATION

    • CACHING OF RESPONSES TO REQUESTS • QUERIES AVOID HITTING PHP SERVER ALTOGETHER LB CACHE NGINX HHVM OBJECT DB SESSION
  6. What is it best for? SUPERFICIAL OPTIMIZATION 1. STATIC SITES

    2. LOGIN NOT REQUIRED 3. CONTENT RARELY CHANGES 4. CONTENT NOT DYNAMIC
  7. WHAT ARE THE PRIMARY TYPES OF CACHING? TYPES OF CACHING

    STATIC FILE CACHING REVERSE PROXY CACHE
  8. Proactively generating a cached copy of content STATIC FILE CACHING

    1. TYPICALLY HANDLED BY WORDPRESS PLUGIN 2. NGINX CAN BE CONFIGURED TO SERVE FILES WITHOUT HITTING PHP 3. CAN BE LOADED INTO VOLATILE MEMORY OR KEY-VALUE STORE FOR MAXIMUM PERFORMANCE
  9. Service cached copy of previously fulfilled requests REVERSE PROXY CACHE

    1. TWO OPTIONS ARE VARNISH AND NGINX 2. MICROCACHING VS LONG TERM CACHING 3. MALLOC (DEFAULT FOR VARNISH)
 4. AVOID RE-RENDERING THE PAGE
  10. LB CACHE NGINX HHVM OBJECT DB SESSION • INCREDIBLE SCALABILITY

    WITH LOW RESOURCE USAGE • LOWEST TTFB (NOTE: NOT SAME AS RUM) • FASTEST RENDERED RESPONSE What are the primary benefits of front end caching? SUPERFICIAL OPTIMIZATION
  11. How does a reverse proxy cache work? VARNISH VARNISH 1.

    RPC RECEIVES REQUEST 2. BASED ON VALIDATION RULES CHECKS MEMORY 3. SERVES REQUEST IF IN MEMORY 4. CAN BE CONFIGURED TO SERVE STALE CONTENT WHILE RE-FETCHING
  12. Alternative to Varnish? NGINX NGINX 1. NOT AS FAST AS

    VARNISH OUT OF THE BOX
 2. MUST BE RECONFIGURED TO USE MALLOC
 3. SUPPORTS SSL TERMINATION
 4. NOT AS ROBUST AS VCL ’S IN VARNISH
  13. Cheat mode for your website?! UP UP DOWN DOWN LEFT

    RIGHT LEFT RIGHT B A START CLOUDFLARE 1. STATIC CACHE WHOLE PAGE WITH PAGERULES
 2. EDGE CACHED (GEO)
 3. COMPATIBLE WITH ANY SERVER
  14. What are some issues with front end caching? WARNING 1.

    PROBLEMATIC WITH MOST TYPES OF SITES 2. CACHE INVALIDATION RULES ARE DIFFICULT 3. ONLY MAKES SENSE FOR STATIC CONTENT
 4. MOST IMPLEMENTATIONS AVOID CACHING ONCE USER IS LOGGED IN
  15. LB CACHE NGINX HHVM OBJECT DB SESSION • OPTIMIZATION OF

    THE ACTUAL WEB APPLICATION • BEST FOR EVERYTHING EXCEPT STATIC SITES • THIS OPTIMIZATION IS DIFFERENT FOR EVERY SITE Focusing on the back-end SUBSTANTIVE OPTIMIZATION
  16. JIT Compiler that will r0x0r your s0x0rs HHVM HHVM 1.

    JIT COMPILER
 2. DROP-IN REPLACEMENT FOR FPM
 3. PASSES UNIT TESTS 100%
 4. CAN USE FPM AS FALLBACK
 5. CAN SHARE REPOS
 6. REPO-AUTHORITATIVE MODE TO AVOID 12 PASS
  17. Object cache for queries and transients REDIS REDIS 1. CACHE

    QUERIES
 2. SIGNIFICANT PERFORMANCE INCREASE FOR LARGE DB OR COMPLEX JOINS (E.G. RCP, WOO)
 3. CAN ACT AS LOCAL CACHE FOR REMOTE DB
 4. OBJECT CACHING HANDLED BY WP PLUGIN
 5. USE QUERY MONITOR TO PROFILE DB QUERIES
  18. Most important but most often overlooked MARIADB & MYSQL MARIADB

    1. MYSQLTUNER
 2. MOST DB INSTALLATIONS DON’T UTILIZE ALL RESOURCES
 3. JOIN TABLES, QUERIES AND VIEWS CAN BE CACHED
 4. AVOID TRANSACTIONAL CACHING BY SETTING
  19. Sometimes you’re the source of suck CODE OPTIMIZATION YOU 1.

    STOP USING THE BUILT IN WP KEY-VALUE STORE
 2. AVOID SERIALIZED ARRAYS IF YOU QUERY THE DATA
 3. USE CUSTOM TABLES AND PROPER INDEXES
 4. NORMALIZE YOUR TABLES
 5. UTILIZE VIEWS FOR QUICK QUERIES (CAN BE CACHED)
  20. Scalable out of the box WORDPRESS SESSIONS WORDPRESS 1. COOKIE

    BASED SESSIONS
 2. SOME PLUGINS REQUIRE PHP SESSIONS
 3. PLUGIN THAT MIMICS PHP SESSIONS WITHIN DB
 4. MEMCACHE
 5. USE CASE DEPENDENT
  21. Handling asset data WORDPRESS ASSET DATA S3 1. UPLOADS FOLDER


    2. CORE ASSETS SHOULD BE DEPLOYED
 3. SHARED VOLUMES (DOCKER ONLY)
 4. NFS / GLUSTERFS
 5. UPLOAD ASSETS TO S3 *
  22. DISTRIBUTED ARCHITECTURE The adventure in Dev Ops LOAD BALANCER MULTIPLE

    NODES SCALABLE LAYERS DISTRIBUTED DB MULTIPLE DC CONCURRENCY Load balancers are used to distribute requests across mul2ple applica2on or web servers U2lize mul2ple processes within a node or mul2ple nodes to distribute processing With Docker, you can use containers to scale each layer independently, even on single server setups For the most data intensive sites, distribute reads across replicated followers (LudicrousDB) Distribute your app servers across mul2ple datacenter or even regions for maximum performance and redundancy Use Capistrano or similar tool to deploy to mul2ple servers concurrently and only go live upon success
  23. Automated PHP stacks by Laravel LARAVEL FORGE HHVM and FPM

    support is baked right in. As a Laravel product, it is made specifically for PHP. Made for PHP Automatically provisions at DigitalOcean, Linode and AWS Provisioning Manage your sites and configuration through the provided interface. Self-Management
  24. Upside FORGE 1. TRADITIONAL CONCEPT 2. EASIER TO SETUP 3.

    ACTUAL VPS Downside 1. LAYERS CAN’T SCALE INDEPENDENTLY 2. MAINTENANCE OF VPS 3. LESS SECURE
 4. REQUIRES VPS FOR EACH INSTANCE
 5. SLOW SPINUP
 6. POST PROVISIONING
  25. FORGE PROCESS What’s the forge process look like? 01 Step

    One CONFIGURE 02 Step Two PROVISION 03 Step Three DEPLOY
  26. Steps to provision the database server on Forge DATABASE 1.

    CREATE APP SERVER WITHIN FORGE THAT WILL SERVER AS THE DEDICATED DB SERVER 2. DATABASE SERVER CAN DOUBLE AS YOUR SHARED DATA SERVER 3. IT IS RECOMMENDED THAT YOU KEEP THIS SERVER INDEPENDENT
  27. Steps to provision an app server on Forge APP SERVER

    1. CREATE APP SERVER 2. CONFIGURE TO USE DB SERVER USING INTERNAL IP 3. MOUNT SHARED FOLDER FROM DB SERVER INTO UPLOADS
 4. RINSE AND REPEAT (N)
  28. Provision a load balancer on Forge LOAD BALANCER 1. CREATE

    LOAD BALANCER IN FORGE 2. SET TO BALANCE TO EACH OF THE APP SERVERS THAT YOU’VE SETUP
  29. What else do I need to know about load balancers?

    LOAD BALANCER 1. TCP BASED LOAD BALANCING UTILIZES THE APP SERVERS FOR SSL TERMINATION 2. IF YOU CHOOSE HTTP LOAD BALANCING AND TERMINATE SSL AT THE LB, MAKE SURE YOU CONFIGURE PHP/WP TO RECOGNIZE THE FORWARDED PROTO 3. CAN CONFIGURE SPDY OR HTTP/2 4. LB TERMINATION OR APP SERVER TERMINATION?
  30. What are some Docker concepts and conventions? DOCKER CONCEPTS 1.

    SINGLE CONCERN 2. STATELESS CONTAINERS 3. ISOLATION (SECURITY) 4. MICRO-CONTAINERS
  31. How do you benefit from Docker? WHY DOCKER? 1. PORTABILITY

    (DEPLOY ANYWHERE) 2. NODES ARE STATELESS (NO PROVISIONING) 3. IMAGES DEPLOY IN SECONDS 4. MULTIPLE SERVICES OR CONTAINERS PER NODE
 5. INDEPENDENT SCALING 6. MINIMAL TO NO SERVER MAINTENANCE
 7. ZERO DOWNTIME UPGRADES
 8. HIGH AVAILABILITY
 9. TRIVIAL UPGRADES
  32. What is Weave and how will it change my life?

    WEAVE 1. NETWORK ACROSS NODES, DATACENTERS, REGIONS AND EVEN PROVIDERS 2. EACH CONTAINER IS ASSIGNED AN INTERNAL IP ADDRESS 3. PORTS ARE OPENED UP INTERNALLY - AND EXPOSED THROUGH WEAVE 4. “LINKS” THAT ARE CREATED BETWEEN SERVICES ARE RESOLVED BY NAME (E.G. MYSQL = 10.1.5.2)
  33. How does Weave handle load balancing with zero configuration? TRIVIAL

    LOAD BALANCING 1. DNS BASED LOAD BALANCING (RESOLUTION)
 2. SINGLE ENTRY IN CONFIGURATION FILES INSTEAD OF CHAIN OF PROXY PASS
 3. WEAVE HANDLES “DISCOVERY” FOR YOU SO YOU DON’T NEED TO WORRY ABOUT ACTIVATING OR DEACTIVATING INSTANCES EXAMPLE: Use just HHVM in nginx configuration
  34. Containerization made accessible through Tutum TUTUM Easy configuration of services

    and stack using the management interface Easy Configuration Automatically provision to DigitalOcean, RackSpace, Microsoft Azure, AWS or BYOB Provisioning Manage services easily including scaling, redeployment and termination Easy Management
  35. What does Tutum do for me? TUTUM 1. AUTOMATICALLY PROVISIONS

    AND TAGS DOCKER NODES
 2. INTERFACE TO EDIT YAML STACK CONFIGURATION
 3. INTERFACE TO EDIT THE CONFIGURATION OF EACH INDIVIDUAL SERVICE
 4. AUTOMATES SCALING, LOGS, ETC
 5. PROVIDES CONSOLE ACCESS INTO INDIVIDUAL CONTAINERS
  36. STACK CONFIGURATION lawfm-nginx: image: 'cook/alpha-nginx-pagespeed:latest' deployment_strategy: high_availability environment: - 'VIRTUAL_HOST=.law.fm'

    links: - 'lawfm-fpm:fpm' - 'lawfm-hhvm:hhvm' - 'lawfm-memcached:memcached' restart: always tags: - lawfm - production target_num_containers: 2 volumes: - '/data/lawfm/home/alpha:/home/alpha' - '/data/lawfm/var/log/nginx:/var/log/nginx' - '/data/lawfm/var/cache/nginx:/var/cache/nginx' - '/data/lawfm/var/ngx_pagespeed_cache:/var/ngx_pagespeed_cache' - '/data/lawfm/etc/nginx/lawfm.conf:/etc/nginx/nginx.conf'
  37. STACK CONFIGURATION lawfm-nginx-proxy: image: 'cook/alpha-proxy-spdy:latest' ports: - '80:80' - '443:443'

    privileged: true restart: always tags: - lawfm - produc2on volumes: - '/var/run/docker.sock:/tmp/docker.sock' - '/data/lawfm/etc/nginx/certs:/etc/nginx/certs'
  38. How do I handle deployment when it’s distributed? DEPLOYMENT 1.

    CAPISTRANO OR ROCKETEER
 2. WEB DIRECTORY IS A SYMBOLIC LINK TO A TIMESTAMPED DEPLOY
 3. SYMBOLIC LINK IS ONLY UPDATED ON SUCCESSFUL DEPLOY
 4. WHOLE BUILDS FOR EACH DEPLOY
 5. ROLLBACK IS JUST A MATTER OF CHANGING THE SYMBOLIC LINK
  39. Funneling your logs into one place LOGGING 1. PAPERTRAIL OR

    LOGENTRIES
 2. AGGREGATE TAIL
 3. FILTER OR SEARCH
 4. CONFIGURE TO TRIGGER NOTIFICATION IN SLACK OR PAGERDUTY
  40. Just what can your stack handle? PERFORMANCE NOTES 1. LINODE

    NODE BALANCERS CAN HANDLE ABOUT 10,000 CONCURRENT CONNECTIONS
 2. BEYOND 10,000 YOU’LL NEED TO START DISTRIBUTING IT ACROSS BALANCERS
 3. 10,000 CONCURRENT USERS = 1,000,000 VISITS AN HOUR (VARIES GREATLY BASED ON USAGE PATTERN)
 4. CONCURRENT CONNECTIONS != CONCURRENT USERS
  41. What kind of testing is worthwhile? PERFORMANCE TESTING 1. FLOODING

    YOUR HOME PAGE GIVES YOU LIMITED FEEDBACK ON ACTUAL SITE PERFORMANCE
 2. LOADIMPACT, BLITZ.IO OR LOADER.IO
 3. LUA SCRIPTS
 4. CHROME PLUGINS
  42. PrimeTime Code https://github.com/primetimecode mysqltuner http://mysqltuner.com/ Load Impact https://loadimpact.com/ Docker https://www,docker.com/

    Tutum https://www.tutum.co/ 01. 03. 04. 02. 05. TOOLS Forge https://forge.laravel.com LudicrousDB https://github.com/johnjamesjacoby/ludicrousdb 06. 07.