Upload
joshua-eichorn
View
599
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Slides from Joshua Eichorn's Scaling WooCommerce Presentation at 2014 WooConf
Citation preview
CONFERENCEJoshua Eichorn, CTO
SCALING WOOCOMMERCE
Joshua EichornCTO Pagely
1
CONFERENCEJoshua Eichorn, CTO
WHO AM I?
‣ CTO of Pagely dealing with WordPress at Scale every day
‣ Long time Open Source Developer, PHPDocumentor, PEAR
‣ Lots of experience with PHP at extreme scale at Stumbleupon
2
CONFERENCEJoshua Eichorn, CTO
WHAT DO WE MEAN BY SCALE?
‣ High volume of traffic
‣ High volume of transactions
‣ Large product catalog
3
CONFERENCEJoshua Eichorn, CTO
TODAY’S FOCUS
‣ High volume of traffic
‣ Large transaction volume is largely a sizing issue
‣ Large product catalog is largely unsolved. Normally this means importing data, importer performance will be your main issue.
4
CONFERENCEJoshua Eichorn, CTO
HAVE REALISTIC EXPECTATIONS
‣ Successful stores generate data (orders, products, reviews)
‣ Don’t expect to host a store for the same cost as a blog
‣ You will need more Mysql capacity: storage, memory, and CPU
‣ You will need more PHP capacity: CPU and memory
‣ You will likely want shell access so you can use WP-CLI for maintenance
5
CONFERENCEJoshua Eichorn, CTO
SCALING WORDPRESS = PAGE CACHING
‣ WordPress scaling has generally focused on page caching using Nginx or Varnish
‣ Most blogs are serving mostly static content
‣ Ecommerce isn’t that different, the majority of your product pages etc are static content
6
CONFERENCEJoshua Eichorn, CTO
PAGELY VPS CACHED
7
CONFERENCEJoshua Eichorn, CTO
PAGELY VPS NO CACHING
8
CONFERENCEJoshua Eichorn, CTO
PERSONALIZATION BREAKS CACHING
‣ Logged in users
‣ Showing the Cart status on every page
‣ Using a plugin that starts a PHP session
‣ Recommendations based on past purchases
9
CONFERENCEJoshua Eichorn, CTO
PERSONALIZATION SHOULDN’T BREAK CACHING
‣ Most sites use very minimal personalization
‣ Option #1: Cache pages unless a specific cookie is set, only set cookie when an item is in the cart
‣ Option #2: Client side personalization
10
CONFERENCEJoshua Eichorn, CTO
CACHE PAGES UNLESS A SPECIFIC COOKIE IS SET
‣ WooCommerce sets the cookie for you
‣ woocommerce_items_in_cart=1
‣ This is an easy solution, no template changes needed
map $http_cookie $no_cache_cookie {default 0;"~woocommerce_" 1;
"~wordpress_" 1;}
server {listen 80;proxy_cache CONTENT;
proxy_cache_min_uses 1;proxy_cache_valid 200 30m;
location / {proxy_no_cache $no_cache_cookie;
proxy_cache_bypass $no_cache_cookie;
proxy_set_header Host $host;proxy_pass http://realserver:80;
}} 11
NGINX Example
CONFERENCEJoshua Eichorn, CTO
CLIENT SIDE PERSONALIZATION
‣ Store the data you need in a cookie
‣ Read the cookie on the client side, update UI
‣ This isn’t happening out of the box so it takes some work
12
CONFERENCEJoshua Eichorn, CTO
WILL CACHING SOLVE EVERYTHING?
‣ Maybe
‣ What does your traffic look like
‣ The more successful you are at driving purchases the less helpful caching is
‣ Use cache purging or low cache times or both
‣ Large catalogs lower cache hit rates
13
CONFERENCEJoshua Eichorn, CTO
WHAT MAKES YOUR SITE SLOW
‣ Running PHP code (uses CPU)
‣ Talking to MySql (waiting)
‣ Talking to an Object Cache (waiting)
‣ Talking to external services (waiting)
‣ Doing fileIO (waiting)
14
CONFERENCEJoshua Eichorn, CTO
THEME/PLUGIN CHOICES CAN MAKE YOUR SITE UN-SCALABLE
‣ Showing 500 products on one page
‣ Dynamic menus that load every page in your site from the DB
‣ Calling a Facebook API on every page load
‣ Loading images over http to get there size
15
CONFERENCEJoshua Eichorn, CTO
HOW TO SIZE YOUR SERVER
‣ PHP-FPM is easier to scale them mod_php
‣ # of workers hard limit is ram
‣ Useful limit is amount of CPU
‣ Run enough concurrent traffic to bring CPU to 100% (ab -c 2 http://localhost/)
‣ Once you reach this point, more workers are trading off speed for concurrency
‣ If that level of concurrency is less then you see in your logs on a regular basis
‣ You need a bigger server or you need to be faster 16
CONFERENCEJoshua Eichorn, CTO
SCALING OUT VS SCALING UP
‣ Bigger servers are easier then many servers
‣ Many servers gets you added reliability as well as more scale
‣ On most cloud platforms it’s the same cost or cheaper to scale up
‣ Splitting out Mysql makes sense in almost all cases, due to different reliability needs
‣ Test splitting out object cache, usage is very round trip heavy, it may be slower
17
CONFERENCEJoshua Eichorn, CTO
SCALING OUT
‣ Scale out webservers:
‣ Direct traffic – Amazon ELB, Nginx, Varnish, Apache mod_proxy
‣ Sync files – DRBD, Lsyncd (Don’t use nfs)
‣ Scale out Mysql:
‣ Master + Read Slaves (doesn’t scale writes)
‣ Hyperdb DB drop-in
‣ Slave lag monitoring is important, HyperDb has examples
18
CONFERENCEJoshua Eichorn, CTO
QUESTIONS
19