high-performance magento in the cloud
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
Magento High Performance
…in the cloud
php[world] 2014 – Washington D.C.
Fabrizio Branca
fbrnc
fbrnc
E-Commerce: Magento
CMS: TYPO3
Portals: ZF, FLOW,…
Mobile Searchperience: SOLR
>120 people world-wide
High Performance
/Scale
Global Enterprise Projects
San Francisco, CA
Janine
Fiona
that’s me
Leo
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...?
PC games (download)
Plush toys, shirts, ...
> 24.000.000 likes > 500.000 followers
Social Media Impact
your application one process of…
execution time
me
mo
ry
that’s your server
…running your application
𝑡𝑜𝑡𝑎𝑙 𝑚𝑒𝑚𝑜𝑟𝑦 = 𝑐𝑜𝑛𝑐𝑢𝑟𝑟𝑒𝑛𝑡 𝑢𝑠𝑒𝑟𝑠 ∗ 𝑚𝑒𝑚𝑜𝑟𝑦/𝑝𝑟𝑜𝑐𝑒𝑠𝑠
256 MB /process
100 users
25 GB RAM
1000 users 250 GB RAM
Option 1 Make your app “smaller”
make it faster! make it
consume less memory!
Option 2 Make your box “bigger”
a.k.a. “vertical scaling”
Option 3 Add more boxes
a.k.a. “horizontal scaling”
Vertical
Scaling
Optimization
Horizontal
Scaling
bigger box
more boxes
smaller “app”
Scaling
Single Server
Multi-Server
vs.
Single server vs. Multi server
What’s the big deal?
Shared nothing?
Session
Storage Cache
Code JS/CSS
bundles
Database Assets
Multi Server Deployment
“Hello World! Free Shipping for everyone!”
“Hello World! Free Shipping for everyone!”
“Check out our new product!”
“Holiday Season!”
Slow response times, server
crashes,…
Waste of money
Waste of money
Slow response times, server
crashes,…
Auto Scaling!
Pay per hour
Actually, it looks more like this
Cloud (in case you haven’t
noticed…:)
Amazon EC2 Amazon S3 Amazon RDS CloudFront
Route 53 ElastiCache Elastic Load
Balancing
Cloud Services
AWS Management
Console RightScale Amazon SWF OpsWorks AWS
CloudFormation
EC2 instance
EC2 instance
Server Array (or “auto-scaling group”)
Based on various metrics
Server Array (or “auto-scaling group”)
EC2 instance
Server Array (or “auto-scaling group”)
EC2 instance
Elastic Architecture
Booting new instances
fully automatic
Auto-healing
Infrastructure as Code
Loose Coupling
No hardcoding! “RightScale API, give
me all frontend servers”
“ELB, here I am”
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
ELB
Backend
Array Frontend
Array
Worker
Array
Varnish
Array
Deployment X
Route 53
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
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
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
Downtime
Number of lost carts
Number of lost sessions and logins
1.000.000 unique visitors. per day.
concurrent users.
Orders.
10
5 6 7
8
9
per second. Yes, per second!
AWS OpsWorks
“DevOps Application Management Service”
Stacks, Layers Instances and Apps
e.g. “production”
Varnish
PHP
DB Instances
Lifecycle Events
Build Installation Deployment Provisioning
Chef
deploy
cookbook
before_
migrate.rb
Jenkins
Setup Conf Deploy
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
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
App Varnish Reverse Proxy
Protecting the application
Only a few requests hit your app!
90%
Varnish Tweaking
Cache Hitrate
80%
Varnish Tweaking
Cache Hitrate
98.6%
Varnish Tweaking
Cache Hitrate
Reduce Number of Requests
… hitting your application
Use a CDN
Offload dynamic
parts
Do Ajax
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
use cookies or localStorage
Don’t Ajax
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
3xx
4xx
5xx
Redirects
Client errors
Cache other status codes
Server errors
http://example.com/
?utm_source=phpworld14
&utm_medium=slides
…and many more.
Normalize URLs
Filter these!
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
Bottleneck Candidates
Dynamic requests are still too slow?
How do you know?
StackDriver New Relic Aoe_Profiler Xdebug
Server
App
Profile! minimal overhead
Knows about Magento… Very
detailed!
RAM & CPU
That’s easy…
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
Growing Data
Trimming the fat!
Orders
Promotions
cms / banners
Aoe_CacheCleaner
Aoe_QuoteCleaner
File I/O
especially on virtual machines!
0
lib
community
core
local
Number of *.php files by location
Less file operations
Aoe_ClassPathCache Magento
Compiler
Solution File I/O
…also check Magento 2!
External Components
Frontend?
Cache Backend?
Web Services?
Webserver?
Bottleneck Candidates
Memory CPU File I/O Database External
Components
Launch!
Deployment
Space game launch!
USA wakes up
http://joind.in/talk/view/11889
Thank you! Any questions?
{firstname}.{lastname}@aoe.com
http://www.aoe.com
http://www.fabrizio-branca.de
@fbrnc Follow me on twitter!
My blog