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

Scaling WordPress - WordCamp Antwerp 2016

Scaling WordPress - WordCamp Antwerp 2016

Slides for my WordPress scalability talk at WordCamp Antwerp 2016. http://2016.antwerp.wordcamp.org

Thijs Feryn

June 04, 2016
Tweet

More Decks by Thijs Feryn

Other Decks in Technology

Transcript

  1. ✓Tremendously popular ✓Even the big boys use it ✓Not the

    best code ✓It does the job ✓Powered by the LAMP stack The context: Wordpress
  2. ✓More RAM ✓Faster disks ✓More database servers ✓Master-slave replication ✓Read/write

    splitting (HyperDB) ✓Query/Object caching (Redis) Optimize database
  3. ✓More RAM ✓Faster disks ✓More/faster CPUs ✓More servers ✓OPCache ✓PHP-FPM

    ✓Recent PHP version ✓HHVM or PHP 7? ✓Nginx or Apache? Optimize runtime
  4. ✓Only GET & HEAD ✓No authorization headers ✓No cookies ✓No

    set-cookies ✓Valid cache-control/expires headers When does Varnish cache? Some rules …
  5. ✓ Remove all cookies & set-cookies from static assets ✓

    Remove all tracking cookies ✓ Don't cache if wordpress_ or comment_ cookies are present ✓ Or just remove all non-Wordpress cookies ✓ Don't cache wp-login or wp-admin pages ✓ Don't cache preview pages ✓ Normalize URL ✓ Anonimize HTTP output ✓ Provide PURGE logic Required VCL changes
  6. vcl 4.0; import std; backend default { .host = "127.0.0.1";

    .port = "8080"; .max_connections = 300; .first_byte_timeout = 100s; .connect_timeout = 10s; .between_bytes_timeout = 5s; } acl purge { "192.168.33.10"; "localhost"; "127.0.0.1"; "::1"; } sub purge_regex { ban("obj.http.X-Req-URL ~ " + req.url + " && obj.http.X-Req-Host == " + req.http.host); } sub purge_exact { ban("obj.http.X-Req-URL == " + req.url + " && obj.http.X-Req-Host == " + req.http.host); } sub purge_page { set req.url = regsub(req.url, "\?.*$", ""); ban("obj.http.X-Req-URL-Base == " + req.url + " && obj.http.X-Req-Host == " + req.http.host); }
  7. <ifModule mod_headers.c> Header set Cache-Control "public, max-age=3600" <filesMatch "\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv| gif|gz|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|otf|

    ogg|ogm|opus|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz| ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)$"> Header set Cache-Control "public, s-maxage=2592000" </filesMatch> </ifModule> Control Time To Live Apache .htaccess
  8. sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache

    = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } Debugging