85
Scaling Data in Magento

Scaling Data in Magento

Embed Size (px)

DESCRIPTION

In this technical session, we will look at how you can scale the database horizontally behind Magento. We will discuss the reasons for scaling through replication and how this may impact on your infrastructure, deployment and Magento implementation. Replication brings with it a great deal of benefits but also some pitfalls and potential problems with things such as high rates of data change. We will present simple solutions with MySQL replication and also using Tungsten by Continuent to bring high availability and high performance to MySQL. This will be backed by real data and metrics from one of the highest volume Magento stores in the UK showing how Magento can be deployed at scale with high availability to serve the UK, USA and Australia from a single implementation generating over $100 million in revenue.

Citation preview

Page 1: Scaling Data in Magento

Scaling Data in Magento

Page 2: Scaling Data in Magento

Alistair SteadCTO

@alistairstead

Page 3: Scaling Data in Magento

Focused seasonal trends such as Cyber Monday have the capacity to melt tin

Page 4: Scaling Data in Magento

Server capacity can of course be expandedhardware is inexpensive...

Page 5: Scaling Data in Magento

Back pressure

from lower systems will block PHP

Page 6: Scaling Data in Magento

When the DB is the bottleneck

adding more servers will only make it worse

Page 7: Scaling Data in Magento

I'm not a DBA

Page 8: Scaling Data in Magento

When your store is popular you have to cope learn

Page 9: Scaling Data in Magento

Don't just copy what is on stackoverflow

identify your exact problem.

Page 10: Scaling Data in Magento

You have to learn to question the current state?

Page 11: Scaling Data in Magento

You have to find people that can help!

Page 12: Scaling Data in Magento

After all engineering is not a solitary affair

Page 13: Scaling Data in Magento

So you have your store up and running...

Page 14: Scaling Data in Magento

All web servers are scaled and running nicely...

Page 15: Scaling Data in Magento

You have Magento configured for optimal

running...

Page 16: Scaling Data in Magento

Now you have more traffic and things are slowing

down...

Page 17: Scaling Data in Magento

What do you do?

Page 18: Scaling Data in Magento

Well... ..?

Page 19: Scaling Data in Magento

You can't do anything with out instrumentation

Page 20: Scaling Data in Magento

Development instrumentationidentify problems early

Page 21: Scaling Data in Magento

Production instrumentation

will show the real problems

Page 22: Scaling Data in Magento

We have metrics that say the DB is a slowing us

down

Page 23: Scaling Data in Magento

We need to take some actions...

Page 24: Scaling Data in Magento

But first...a brief interlude

Page 25: Scaling Data in Magento

Scaling, high availability and redundancy

All related but separate things

Page 26: Scaling Data in Magento

Scaling:

The ability to function within acceptable limits as the number of users increases

Page 27: Scaling Data in Magento

High availability:

The ability to facilitate continuous function following and during failure

Page 28: Scaling Data in Magento

Redundancy:

Duplication of critical systems so as to have no single point of failure

Page 29: Scaling Data in Magento

In a mission critical application

all these need to be balanced

Page 30: Scaling Data in Magento

In commerceconversion rates are directly effected

the decisions made in these areas

Page 31: Scaling Data in Magento

Technology should facilitate conversion!

Page 32: Scaling Data in Magento

So where should we start?

Page 33: Scaling Data in Magento

The Apache / Nginx process is blocking

waiting on PHP...

PHP is waiting on the Database...

Page 34: Scaling Data in Magento

Step 1Make your queries FASTer

Page 35: Scaling Data in Magento

MySQL IndexesIdentify missing indexes for a query

and speed up the result

Page 36: Scaling Data in Magento

Re-design queriesNot recommended for core queries but

sometimes you have to...

However send a patch back to Magento for inclusion in the next release

Page 37: Scaling Data in Magento

Step 2Cache as much as you can

Page 38: Scaling Data in Magento

Expand query cache as much as you can

Can you fit your entire DB into memory?

Page 39: Scaling Data in Magento

Use Full Page Cache

State the obvious but it protects the database at peak loads

Page 40: Scaling Data in Magento

Use proxy or edge caches

If you don't need to execute PHP don't

Page 41: Scaling Data in Magento

At some point your cache MUST expire

On highly merchandised sites then cache is simply not as effective

Page 42: Scaling Data in Magento

But this is all for read operations...

What about writing data?

Page 43: Scaling Data in Magento

Lock wait timeout...

Have you seen this in your exception log?

Page 44: Scaling Data in Magento

Step 4Ensure all tables are INNODB

Some legacy code will have created MYISAM

Page 45: Scaling Data in Magento

Increase lock_wait_timeout

Don't this is an anti-pattern

Page 46: Scaling Data in Magento

Step 5Transaction level

Page 47: Scaling Data in Magento

Use READ COMMITTED

instead of the MySQL default of REPEATABLE READ

Page 48: Scaling Data in Magento

Step 6Reduce transaction size

Page 49: Scaling Data in Magento

Your transaction is not committed?

Your waiting for external service calls or none critical writes...

Page 50: Scaling Data in Magento

Step 7Reducing non-critical write operations

Page 51: Scaling Data in Magento

Logging can be done somewhere elese<?xml version="1.0" encoding="UTF-8"?><frontend> <events> <controller_action_predispatch> <observers><log><type>disabled</type></log></observers> </controller_action_predispatch> <controller_action_postdispatch> <observers><log><type>disabled</type></log></observers> </controller_action_postdispatch> <customer_login> <observers><log><type>disabled</type></log></observers> </customer_login> <customer_logout> <observers><log><type>disabled</type></log></observers> </customer_logout> <sales_quote_save_after> <observers><log><type>disabled</type></log></observers> </sales_quote_save_after> <checkout_quote_destroy> <observers><log><type>disabled</type></log></observers> </checkout_quote_destroy> </events></frontend>

Page 52: Scaling Data in Magento

HTTP 101Only modify state on HTTP POST

#TIP 1. This simple rule can help so many aspects of scaling

Page 53: Scaling Data in Magento

Off-load functionality to third parties

logging and tracking can be handled else where

Page 54: Scaling Data in Magento

Move data and logic to the client

If state has not changed then the client should know all it needs to know

Page 55: Scaling Data in Magento

Step 8Asynchronous write operations

Page 56: Scaling Data in Magento

Use job queues

non-crtitical write operations can be pushed to the queue

You then have to work with eventual consistency

Page 57: Scaling Data in Magento

Step 9Clustering & replication

Page 58: Scaling Data in Magento

Introduce a slave databaseReplicate data to the slave database

Page 59: Scaling Data in Magento

Use standard MySQL replication

Enable binary logging

Page 60: Scaling Data in Magento

Ensure you have compression enabled!

Or you will flood you internal network

Page 61: Scaling Data in Magento

Use MIXED Binary logging format

for quicker replication

Page 62: Scaling Data in Magento

STATEMENT Binary logging

Can cause PK clashes... in our experience...

Page 63: Scaling Data in Magento

Single threaded replication

Prior to MySQL 5.6 you only have one thread

Page 64: Scaling Data in Magento

Split read from write operations

Across the cluster

Page 65: Scaling Data in Magento

Write, read consistency

Can be resolved with module level connections

Page 66: Scaling Data in Magento

Module config.xml

<?xml version="1.0" encoding="UTF-8"?><config> <global> <resources> <module_read> <connection> <use>core_write</use> </connection> </module_read> </resources> </global></config>

Page 67: Scaling Data in Magento

Cluster & replication options

Page 68: Scaling Data in Magento

Tungsten

Page 69: Scaling Data in Magento

Replicator

A multi-threaded replication process over MySQL

Page 70: Scaling Data in Magento

Connection manager

A smart connection manager that can filter based on query content

Page 71: Scaling Data in Magento

High availability

Connection manager provides active service discovery

Page 72: Scaling Data in Magento

Connection Manager

runs on every server and allows the master to float around the cluster

Page 73: Scaling Data in Magento

Hot production upgrades

MySQL can be configured or upgraded with zero downtime

Page 74: Scaling Data in Magento

The Master Database

Can be moved to any node without config changes or downtime

Page 75: Scaling Data in Magento

Service discovery

All servers connect to their own Connection Manager

Page 76: Scaling Data in Magento

Next steps...

Page 77: Scaling Data in Magento

One setting does not rule them all

Use many tuned connections for specific operations types

Page 78: Scaling Data in Magento

Alternate replication architecture

Fan-in for example allowing multiple masters

Page 79: Scaling Data in Magento

Sharding

The smart connector can re-write the query on the fly

Page 80: Scaling Data in Magento

Gotchas...

Page 81: Scaling Data in Magento

Turn off security updates because your cluster will FAIL

Page 82: Scaling Data in Magento

Ensure enough RAM for the transaction size

Page 83: Scaling Data in Magento

Do you have enough file descriptors

This will be limited ensure you have enough

Page 84: Scaling Data in Magento

Thank you!

Questions?

Page 85: Scaling Data in Magento

http://bit.ly/sdinmage