high-performance magento in the cloud

85
Magento High Performance …in the cloud php[world] 2014 Washington D.C.

Upload: aoe

Post on 02-Jul-2015

1.991 views

Category:

Technology


3 download

DESCRIPTION

The Angry Birds global web shop (at times the highest traffic Magento platform in the world) runs on Magento Enterprise, scales 100% automatically in the AWS infrastructure and is designed to easily handle 20x traffic peaks during marketing and new release peaks. Learn how to implement a Magento store for optimal performance, how to run it in a cloud environment, about the infrastructure and the applied strategies for continuous delivery, auto-scaling and zero-downtime rollouts.

TRANSCRIPT

Page 1: High-Performance Magento in the Cloud

Magento High Performance

…in the cloud

php[world] 2014 – Washington D.C.

Page 2: High-Performance Magento in the Cloud

Fabrizio Branca

Page 3: High-Performance Magento in the Cloud

fbrnc

fbrnc

Page 4: High-Performance Magento in the Cloud
Page 5: High-Performance Magento in the Cloud

E-Commerce: Magento

CMS: TYPO3

Portals: ZF, FLOW,…

Mobile Searchperience: SOLR

>120 people world-wide

High Performance

/Scale

Global Enterprise Projects

Page 6: High-Performance Magento in the Cloud

San Francisco, CA

Janine

Fiona

that’s me

Leo

Page 7: High-Performance Magento in the Cloud
Page 8: High-Performance Magento in the Cloud

Who’s runs a shop with

10 orders/hour?

Who’s runs a shop with

10 orders/min?

Who’s runs a shop with

10 orders/sec?

YOU...?

Page 9: High-Performance Magento in the Cloud
Page 10: High-Performance Magento in the Cloud

PC games (download)

Plush toys, shirts, ...

Page 11: High-Performance Magento in the Cloud

> 24.000.000 likes > 500.000 followers

Social Media Impact

Page 12: High-Performance Magento in the Cloud

your application one process of…

execution time

me

mo

ry

Page 13: High-Performance Magento in the Cloud
Page 14: High-Performance Magento in the Cloud

that’s your server

…running your application

Page 15: High-Performance Magento in the Cloud

𝑡𝑜𝑡𝑎𝑙 𝑚𝑒𝑚𝑜𝑟𝑦 = 𝑐𝑜𝑛𝑐𝑢𝑟𝑟𝑒𝑛𝑡 𝑢𝑠𝑒𝑟𝑠 ∗ 𝑚𝑒𝑚𝑜𝑟𝑦/𝑝𝑟𝑜𝑐𝑒𝑠𝑠

256 MB /process

100 users

25 GB RAM

1000 users 250 GB RAM

Page 16: High-Performance Magento in the Cloud

Option 1 Make your app “smaller”

make it faster! make it

consume less memory!

Page 17: High-Performance Magento in the Cloud

Option 2 Make your box “bigger”

a.k.a. “vertical scaling”

Page 18: High-Performance Magento in the Cloud

Option 3 Add more boxes

a.k.a. “horizontal scaling”

Page 19: High-Performance Magento in the Cloud

Vertical

Scaling

Optimization

Horizontal

Scaling

bigger box

more boxes

smaller “app”

Scaling

Page 20: High-Performance Magento in the Cloud

Single Server

Multi-Server

vs.

Single server vs. Multi server

What’s the big deal?

Page 21: High-Performance Magento in the Cloud

Shared nothing?

Session

Storage Cache

Code JS/CSS

bundles

Database Assets

Page 22: High-Performance Magento in the Cloud

Multi Server Deployment

Page 23: High-Performance Magento in the Cloud

“Hello World! Free Shipping for everyone!”

Page 24: High-Performance Magento in the Cloud
Page 25: High-Performance Magento in the Cloud

“Hello World! Free Shipping for everyone!”

“Check out our new product!”

“Holiday Season!”

Page 26: High-Performance Magento in the Cloud

Slow response times, server

crashes,…

Page 27: High-Performance Magento in the Cloud

Waste of money

Page 28: High-Performance Magento in the Cloud

Waste of money

Slow response times, server

crashes,…

Page 29: High-Performance Magento in the Cloud

Auto Scaling!

Pay per hour

Page 30: High-Performance Magento in the Cloud

Actually, it looks more like this

Page 31: High-Performance Magento in the Cloud

Cloud (in case you haven’t

noticed…:)

Page 32: High-Performance Magento in the Cloud
Page 33: High-Performance Magento in the Cloud

Amazon EC2 Amazon S3 Amazon RDS CloudFront

Route 53 ElastiCache Elastic Load

Balancing

Cloud Services

AWS Management

Console RightScale Amazon SWF OpsWorks AWS

CloudFormation

Page 34: High-Performance Magento in the Cloud

EC2 instance

Page 35: High-Performance Magento in the Cloud

EC2 instance

Server Array (or “auto-scaling group”)

Based on various metrics

Page 36: High-Performance Magento in the Cloud

Server Array (or “auto-scaling group”)

EC2 instance

Page 37: High-Performance Magento in the Cloud

Server Array (or “auto-scaling group”)

EC2 instance

Page 38: High-Performance Magento in the Cloud

Elastic Architecture

Booting new instances

fully automatic

Auto-healing

Infrastructure as Code

Page 39: High-Performance Magento in the Cloud

Loose Coupling

No hardcoding! “RightScale API, give

me all frontend servers”

“ELB, here I am”

Page 40: High-Performance Magento in the Cloud

S3

Deployment X

Backend

Array Frontend

Array

Worker

Array

Varnish

Array

S3 RDS ElastiCache

CloudFront CloudFront Route 53

shop.angrybirds.com

Braintree

Mail DRM

Giftcards

ELB

Page 41: High-Performance Magento in the Cloud

ELB

Backend

Array Frontend

Array

Worker

Array

Varnish

Array

Deployment X

Route 53

Page 42: High-Performance Magento in the Cloud

Deployment X+1 ELB

Backend

Array Frontend

Array

Worker

Array

Varnish

Array

Deployment X

Route 53

ELB

Backend

Array Frontend

Array

Worker

Array

Varnish

Array

Page 43: High-Performance Magento in the Cloud

Backend

Array Frontend

Array

Worker

Array

Varnish

Array

Deployment X

Route 53

Backend

Array Frontend

Array

Worker

Array

Varnish

Array

Deployment X+1 ELB ELB

Page 44: High-Performance Magento in the Cloud

Route 53

Backend

Array Frontend

Array

Worker

Array

Varnish

Array

Deployment X+1

Backend

Array Frontend

Array

Worker

Array

Varnish

Array

Deployment X ELB ELB

Page 45: High-Performance Magento in the Cloud

Downtime

Number of lost carts

Number of lost sessions and logins

Page 46: High-Performance Magento in the Cloud

1.000.000 unique visitors. per day.

Page 47: High-Performance Magento in the Cloud

concurrent users.

Page 48: High-Performance Magento in the Cloud

Orders.

10

5 6 7

8

9

per second. Yes, per second!

Page 49: High-Performance Magento in the Cloud

AWS OpsWorks

“DevOps Application Management Service”

Page 50: High-Performance Magento in the Cloud

Stacks, Layers Instances and Apps

e.g. “production”

Varnish

PHP

DB Instances

Page 51: High-Performance Magento in the Cloud

Lifecycle Events

Page 52: High-Performance Magento in the Cloud

Build Installation Deployment Provisioning

Chef

deploy

cookbook

before_

migrate.rb

Jenkins

Setup Conf Deploy

Page 53: High-Performance Magento in the Cloud
Page 54: High-Performance Magento in the Cloud
Page 55: High-Performance Magento in the Cloud

Route 53

ELB

CloudFront:

Theme (JS/CSS,…)

CloudFront:

media files

Internet

S3:

media

files

S3: build

packages

Continuous

Integration

Pipeline (Jenkins)

OpsWorks

Availability Zone

AWS

CloudFormation

CloudWatch

✓inherently fault tolerant

✓ ✓ ✓

Redis:

Sessions Redis:

Cache Backend RDS DB

instance

RDS DB

instance standby

(Multi-AZ)

✓ ✓

Auto Scaling Group

Frontend Layer Backend Layer

Worker Layer

Varnish Layer

Data Layer

RDS DB Read

replica (for

reports)

Redis:

Full page cache

backend

Production

Stack

External Services

(Fulfillment, DRM,

Giftcards,…)

SES:

Transactional

emails

SQS:

Queue

OpsWorks Setup

“Stack” (= Environment)

“Layers”

App Instances

Page 56: High-Performance Magento in the Cloud

Varnish Custom Layer

Redis Cache

Redis Sessions

Custom Layer

Magento Production,

Magento Staging,

Wordpress,…

PHP App Layer

MySQL DB Layer

Minimal Setup

Route 53

ELB

CloudFront:

Theme

(JS/CSS,…)

Internet

✓ ✓

S3: build

packages

Continuous

Integration

Pipeline

(Jenkins)

reuse instance for multiple layers

Not recommended! Just a thought experiment…

< $120/month for a c3.2xlarge

Page 57: High-Performance Magento in the Cloud

App Varnish Reverse Proxy

Protecting the application

Only a few requests hit your app!

Page 58: High-Performance Magento in the Cloud

90%

Varnish Tweaking

Cache Hitrate

Page 59: High-Performance Magento in the Cloud

80%

Varnish Tweaking

Cache Hitrate

Page 60: High-Performance Magento in the Cloud

98.6%

Varnish Tweaking

Cache Hitrate

Page 61: High-Performance Magento in the Cloud

Reduce Number of Requests

… hitting your application

Page 62: High-Performance Magento in the Cloud

Use a CDN

Page 63: High-Performance Magento in the Cloud

Offload dynamic

parts

Do Ajax

Page 64: High-Performance Magento in the Cloud
Page 65: High-Performance Magento in the Cloud
Page 66: High-Performance Magento in the Cloud

Request a page (HTTP Request)

deliver static page

Request

Delivering static content

Placeholders for dynamic parts.

Cache-Control headers

Ajax call request dynamic parts

and transfers the id of the currently visited product

JSON response with dynamic content

Replace placeholder

Write session id to cookie

Render the page

Browser Varnish Application

Page 67: High-Performance Magento in the Cloud

use cookies or localStorage

Don’t Ajax

Page 68: High-Performance Magento in the Cloud

Request a page (HTTP Request)

deliver static page

Request

Delivering static content

Placeholders for dynamic parts.

Cache-Control headers

Ajax call request dynamic parts

and transfers the id of the currently visited product

JSON response with dynamic content

Replace placeholder

Write session id to cookie

Render the page

Browser Varnish Application

Page 69: High-Performance Magento in the Cloud

3xx

4xx

5xx

Redirects

Client errors

Cache other status codes

Server errors

Page 70: High-Performance Magento in the Cloud

http://example.com/

?utm_source=phpworld14

&utm_medium=slides

…and many more.

Normalize URLs

Filter these!

Page 71: High-Performance Magento in the Cloud

Reduce Number of Requests

… hitting your application

Don’t Ajax Do Ajax

3xx

4xx

5xx

Cache other

status codes

http://example.com/

?utm_source=pw14

&utm_medium=slides

Normalize URLs Use a CDN

Page 72: High-Performance Magento in the Cloud

Bottleneck Candidates

Dynamic requests are still too slow?

Page 73: High-Performance Magento in the Cloud

How do you know?

Page 74: High-Performance Magento in the Cloud

StackDriver New Relic Aoe_Profiler Xdebug

Server

App

Profile! minimal overhead

Knows about Magento… Very

detailed!

Page 75: High-Performance Magento in the Cloud

RAM & CPU

That’s easy…

Page 76: High-Performance Magento in the Cloud

Database That’s not so easy…

offload the database

less queries (caching!)

more efficient queries (indexes,…)

scaling

sharding

master/slave Percona Toolkit (slow) query log

Page 77: High-Performance Magento in the Cloud

Growing Data

Trimming the fat!

Orders

Promotions

cms / banners

Aoe_CacheCleaner

Aoe_QuoteCleaner

Page 78: High-Performance Magento in the Cloud

File I/O

especially on virtual machines!

Page 79: High-Performance Magento in the Cloud

0

lib

community

core

local

Number of *.php files by location

Less file operations

Page 80: High-Performance Magento in the Cloud

Aoe_ClassPathCache Magento

Compiler

Solution File I/O

…also check Magento 2!

Page 81: High-Performance Magento in the Cloud

External Components

Frontend?

Cache Backend?

Web Services?

Webserver?

Page 82: High-Performance Magento in the Cloud

Bottleneck Candidates

Memory CPU File I/O Database External

Components

Page 83: High-Performance Magento in the Cloud

Launch!

Deployment

Space game launch!

USA wakes up

Page 84: High-Performance Magento in the Cloud

http://joind.in/talk/view/11889

Page 85: High-Performance Magento in the Cloud

Thank you! Any questions?

{firstname}.{lastname}@aoe.com

http://www.aoe.com

http://www.fabrizio-branca.de

@fbrnc Follow me on twitter!

My blog