Top Banner
A Tale of Two Systems David Newman @darthhexx
112

A Tale of 2 Systems

Apr 12, 2017

Download

Technology

David Newman
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A Tale of 2 Systems

A Tale of Two SystemsDavid Newman @darthhexx

Page 2: A Tale of 2 Systems

Howdy! We're the people behind WordPress.com, WooCommerce,

Jetpack, and a bunch of other products for WordPress.

Page 3: A Tale of 2 Systems

We are passionate about making the web a better place. We don't build software for free

– we build it for freedom.

Page 4: A Tale of 2 Systems
Page 5: A Tale of 2 Systems

Communication is oxygen

Page 6: A Tale of 2 Systems

A TALE OF TWO SYSTEMS

Page 7: A Tale of 2 Systems
Page 8: A Tale of 2 Systems

WordPress.com

WordPress multisite with 100+ million sites.

VIP GoContainer-based VIP WordPress hosting.

Page 9: A Tale of 2 Systems

A TALE OF TWO SYSTEMS

WordPress.com

Page 10: A Tale of 2 Systems

Simplicity scales.

Page 11: A Tale of 2 Systems

WordPress.com

• The App • Database • Static content • Caching • Distributing workload

Page 12: A Tale of 2 Systems

WordPress.com

• Networking • Protecting • Continuous Integration • Stats and analysis

Page 13: A Tale of 2 Systems

The App

Page 14: A Tale of 2 Systems

• Free Open Source Software. • Most widely adopted server-

side programming language. • Notable performance increase

in PHP7.

Page 15: A Tale of 2 Systems

• Free Open Source Software. • 27% of top 10 million sites. • Passionately developed and

supported.

Page 16: A Tale of 2 Systems

• Add/remove/apply filters and actions, offers extensibility.

• We customise, add features and improve performance.

Page 17: A Tale of 2 Systems

• HyperDB • Object Cache • CSS/JS concatenation • 2FA • many, many more…

WordPress.com

Page 18: A Tale of 2 Systems
Page 19: A Tale of 2 Systems

Databases

Page 20: A Tale of 2 Systems

Databases

A billion+ tables

Page 21: A Tale of 2 Systems

HyperDB

• Slave lag and failed host detection and mitigation.

• Distributed reads / writes. • Replication and partitioning

support.

Page 22: A Tale of 2 Systems

Partitioning

• Global tables for sites, blogs, users, usermeta, etc.

• Sharded blog specific data (posts, comments, options, terms, etc.)

Page 23: A Tale of 2 Systems

Databases

• Query comments containing the URL in order to track down errant code.

• Dedicated replicated read-only DBs for backups.

Page 24: A Tale of 2 Systems

Databases

• “Index all the things” and EXPLAIN everything :)

• Use MyISAM, unless workload warrants the use of InnoDB, due to memory requirements.

Page 25: A Tale of 2 Systems

Static Content

Page 26: A Tale of 2 Systems

Life Without Static Content

Page 27: A Tale of 2 Systems

Images

• Distributed fault tolerant file system with MogileFS.

• Clusters in multiple Datacenters.

• Replicated to S3 as immutable backups.

Page 28: A Tale of 2 Systems

Images

• Do not store intermediate sizes.

• Resize images on the fly. • Responsive design with srcset.

Page 29: A Tale of 2 Systems

Images

• Perform image optimisations with pngquant, optipng, and jpegoptim.

• Output progressive JPEGs.

Page 30: A Tale of 2 Systems

Images

• On-the-fly WebP conversions based on HTTP Accept header.

• Disable advanced compression routines under load.

Page 31: A Tale of 2 Systems

CSS/JS

• Dedicated static content production servers.

• Minified at commit. • Concatenated on the fly in

production.

Page 32: A Tale of 2 Systems

Caching

Page 33: A Tale of 2 Systems

Cache Levels

• Server-side • Datacenter • PoP / Edge

Page 34: A Tale of 2 Systems

PHP OpCache

• Compiled PHP scripts cached. • Linked into our deploy system

to auto-compile / delete as necessary.

Page 35: A Tale of 2 Systems

PHP APCu

• Great for “persistent statics”. • Querying load in order to

switch off non-critical image optimisations.

• File system IO processes for consistently hashed services.

Page 36: A Tale of 2 Systems

Datacenter Cache

• Distribution requires shared caches.

• Object Cache shards cache groups.

Page 37: A Tale of 2 Systems

Memcached

• Drop in Object Cache replacement: wordpress.org/extend/plugins/memcached/

• Internal systems for sync’ing DC caches.

Page 38: A Tale of 2 Systems

• Multi-DC replication challenge with DB vs Cache replication timing.

• Sync’ing cache invalidations with DB replication, e.g. Facebook’s mcrouter

Memcached

Page 39: A Tale of 2 Systems
Page 40: A Tale of 2 Systems

Batcache

• Uses Memcached to store and serve rendered pages:wordpress.org/plugins/batcache/

• 40x reduction in page generation time.

Page 41: A Tale of 2 Systems

NGiNX DC Cache

• Caching of some assets at the DC level, e.g. feeds, sitemaps, some images, etc.

Page 42: A Tale of 2 Systems
Page 43: A Tale of 2 Systems

PoP / Edge Caching

• Every “corner” of the world. • Only cache after more than X

page queries in Y time period. • OpenResty for advanced

features.

Page 44: A Tale of 2 Systems

PoP/Edge Invalidations

• Performed using mangle, an internally developed tool.

• Employs Anycast, using encrypted UDP, and a gossip protocol.

Page 45: A Tale of 2 Systems

Distribute

Page 46: A Tale of 2 Systems

DistributeUse the right tool for the job at hand.

Page 47: A Tale of 2 Systems

Async Jobs System

• WordPress-based jobs system. • Time insensitive processes

performed asynchronously. • wp-cron jobs, do_pings, etc.

Page 48: A Tale of 2 Systems

• “Index all the things”. • Used for performant full text

searches on content.

Page 49: A Tale of 2 Systems

• Centralised application log storage.

• Logs shipped via Logcourier. • Kibana for dashboards and

alerts.

Page 50: A Tale of 2 Systems

Networking

Page 51: A Tale of 2 Systems
Page 52: A Tale of 2 Systems

Networking

• HA via Anycast. • Custom server ToR setup using

VRRP. • Production traffic routing.

Page 53: A Tale of 2 Systems

Unicast

Page 54: A Tale of 2 Systems

Broadcast

Page 55: A Tale of 2 Systems

Multicast

Page 56: A Tale of 2 Systems

Anycast

Page 57: A Tale of 2 Systems

Anycast

Page 58: A Tale of 2 Systems

Anycast

• BGP advertises IP address subnets between networks.

• Local preference metric, which overrides the network hop metric (AS Path), adds peering complications.

Page 59: A Tale of 2 Systems

Anycast

Page 60: A Tale of 2 Systems
Page 61: A Tale of 2 Systems
Page 62: A Tale of 2 Systems

Anycast Benefits

• Distributed caches. • Low network latency to closest

PoP. • Easier to perform maintenance. • DDoS mitigation.

Page 63: A Tale of 2 Systems

170Gbps DDoS Absorption

Page 64: A Tale of 2 Systems

Custom ToR Setup

Not this ToR :)

Page 65: A Tale of 2 Systems

• Anycast between ToR and cores.

• VRRP using the host as the bridge between the 2 ToR switches.

Custom ToR Setup

Page 66: A Tale of 2 Systems

• VRRP is active/passive virtual address that can exist on one of 2 devices.

• VRRP master used as the host gateway.

Custom ToR Setup

Page 67: A Tale of 2 Systems

• Multichassis Link Aggregation (MLAG) to form 1 LACP port channel.

• Provides active/active on Layer 2.

Custom ToR Setup

Page 68: A Tale of 2 Systems

Custom ToR Setup

Host

Switch BSwitch A

DCBGP

VRRP MLAG / LACP

VRRP MLAG / LACP

BGP

Page 69: A Tale of 2 Systems

• IP address allocation is efficient.

• Sub-second failover. • Easier switch maintenance. • L3 straight to the server, L2

domain is the server itself.

Custom ToR Setup

Page 70: A Tale of 2 Systems

• Route certain endpoints and content types to specialised backends, e.g. API, wp-admin, statics, etc.

• Global traffic balancing using NGiNX split_clients.

Production Traffic Routing

Page 71: A Tale of 2 Systems

Protecting

Page 72: A Tale of 2 Systems

If you build it, they will come.

Page 73: A Tale of 2 Systems

• Anycast absorbs DDoS by design.

• SSL everywhere using Let’s Encrypt.

Protecting

Page 74: A Tale of 2 Systems
Page 75: A Tale of 2 Systems

• IPSET auto-blocking mechanisms.

• OpenResty for SSL blocking algorithms in NGiNX.

Protecting

Page 76: A Tale of 2 Systems

Comment SPAM

Page 77: A Tale of 2 Systems

Akismet

Filters for spam comments on millions of sites in real time.

Page 78: A Tale of 2 Systems

CI

Page 79: A Tale of 2 Systems

CI

Page 80: A Tale of 2 Systems

• Each engineer has one. • Production test/staging sites. • Huge advantage for production

debugging. • Integrated deploy tests and

validations.

Sandbox

Page 81: A Tale of 2 Systems

• Parallel tests using Agents. • Supports PHPunit tests. • Local sandboxed test data.

TeamCity

Page 82: A Tale of 2 Systems

Stats and Analysis

Page 83: A Tale of 2 Systems

• Tracks for user events. • Sqoop’d into Hadoop and

accessed via Hue2. • Cloudera, Impala, Zookeeper,

etc.

Stats and Analysis

Page 84: A Tale of 2 Systems

A TALE OF TWO SYSTEMS

VIP Go

Page 85: A Tale of 2 Systems

Outline

• Shared infrastructure; isolated client platform.

• No restrictions set on plugins. • Seamless deploy to Dev, Test,

Staging and Production. • Integrated review process.

Page 86: A Tale of 2 Systems

chroot > solution < VM

Page 87: A Tale of 2 Systems

Containers

Page 88: A Tale of 2 Systems

Docker or pure LXC?

Page 89: A Tale of 2 Systems
Page 90: A Tale of 2 Systems

Helicopter View

• Container-based hosting

platform. • Internal Docker Registry. • Custom container orchestration

via Host Action queues. • API driven.

Page 91: A Tale of 2 Systems

Similarities

• Static content • Protecting • Distributing workload

Page 92: A Tale of 2 Systems

Distinctions

• The App Containers • Networking • Caching • Continuous Integration • Auto-scaling

Page 93: A Tale of 2 Systems

App Containers

Page 94: A Tale of 2 Systems

App Containers

• Web and DB containers use Docker as one would LXC, with `/sbin/init`.

• Memcached Docker-style. • AUFS only. • Pin to Docker version.

Page 95: A Tale of 2 Systems

App Containers

• DB containers are InnoDB only. • Percona XtraBackup tools. • Web Containers have Jetpack

Premium installed. • New Relic real time PHP

analysis.

Page 96: A Tale of 2 Systems

Networking

Page 97: A Tale of 2 Systems

Networking

• Avoid using the NAT userspace docker-proxy where possible.

• Use “host-only” wherever possible.

• Dynamic service port assignment via container orchestration.

Page 98: A Tale of 2 Systems

Networking

• Dynamic service port firewall in the containers.

• Set ephemeral port range in net.ipv4.ip_local_port_range.

• Watch the conntrack table!

Page 99: A Tale of 2 Systems

Caching

Page 100: A Tale of 2 Systems

Caching

• Varnish caches all assets at the Edge.

• Be weary of `Hit-for-pass`. • Websockets need special

configs and attention.

Page 101: A Tale of 2 Systems

Caching

• Varnish and TLS, the short story.

• Leap second, design for failure.

Page 102: A Tale of 2 Systems

Continuous Integration

Page 103: A Tale of 2 Systems

Continuous Integration

• Git-centric (Github / Gitlab). • Clients select their own CI / Test

toolchain. • Review Queue integration.

Page 104: A Tale of 2 Systems

Continuous Integration

• Dev / Staging / Production tied to repo branches.

• Host Action controlled code deploys triggered by WebHooks.

Page 105: A Tale of 2 Systems

Stats and Auto-scaling

Page 106: A Tale of 2 Systems

Auto-scaling

• InfluxDB timeseries stats. • API auto-allocates containers to

hosts using signals from host stats.

Page 107: A Tale of 2 Systems

Auto-scaling

• Auto-scaling service interrogates InfluxDB stats and scales reactively.

• Predictive resource allocation using Machine Learning.

Page 108: A Tale of 2 Systems

Summary

• Shard DBs or Clients :) • Cache at the Edge. • Anycast whenever you can. • Employ simple active defences.

Page 109: A Tale of 2 Systems

Summary

• Design for failure. • Sync invalidations with data

streams. • Employ AI for resource

planning.

Page 110: A Tale of 2 Systems

Simplicity scales :)

Page 111: A Tale of 2 Systems

Q & A

Page 112: A Tale of 2 Systems

Thanks

David Newman @darthhexx