Top Banner
HA Architecture in DP MMM & Memcached 卢钧轶@DP
52

MMM&Memcache in DP

Aug 10, 2015

Download

Documents

cenalulu
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: MMM&Memcache in DP

HA Architecture in DPMMM & Memcached

卢钧轶@DP

Page 2: MMM&Memcache in DP

Web

MemcachedCluster

MMM

HA in DP

WriterDB

ReaderDB

memcache

Web1 Web2 Web3

memcache memcache

Page 3: MMM&Memcache in DP

MMM

Page 4: MMM&Memcache in DP

What is MMM

● Perl● Message between Monitor & Agent● Auto Failover for M/S

but MMM is not:● SQL router● Load Balancer

Page 5: MMM&Memcache in DP

Products like MMM

● MHA● LVS + Heartbeat● Pacemaker + Heartbeat

Page 6: MMM&Memcache in DP

MMM Internals

Monitorwhile(){

process_check_resultscheck_host_statesprocess_commandsdistribute_rolesend_status_to_agents

}

Agentwhile( read socket){

handle_command}

Page 7: MMM&Memcache in DP

MMM architecture

Monitor

Slave

Master

Slave

Master

Page 8: MMM&Memcache in DP

MMM architecture

Monitor

Slave

Master

Slave

Master

Page 9: MMM&Memcache in DP

How MMM Do Failover

Monitor

Slavevip3

Mastervip1

Slavevip4

Mastervip2

Page 10: MMM&Memcache in DP

How MMM Do Failover

Monitor

Slavevip3

Mastervip1

Slavevip4

Mastervip2set global read_only=1

Page 11: MMM&Memcache in DP

How MMM Do Failover

Monitor

Slavevip3

Master

Slavevip4

Mastervip2remove VIP

Page 12: MMM&Memcache in DP

How MMM Do Failover

Monitor

Slavevip3

Master

Slavevip4

Mastervip2

select MASTER_POS_WAIT()

Page 13: MMM&Memcache in DP

How MMM Do Failover

Monitor

Slavevip3

Master

Slavevip4

Mastervip2

show master status

Page 14: MMM&Memcache in DP

How MMM Do Failover

Monitor

Slavevip3

Master

Slavevip4

Mastervip2

change master to

Page 15: MMM&Memcache in DP

How MMM Do Failover

Monitor

Slavevip3

Master

Slavevip4

Mastervip1&vip2

vip1 online

Page 16: MMM&Memcache in DP

MMMMMM in DP

Page 17: MMM&Memcache in DP

MMM in DP

Frontend Groupvip1 & vip2

Backend Groupvip3 & vip4

Job Groupvip5

Slavevip3 / vip5

Mastervip1

Slavevip4

Mastervip2

Page 18: MMM&Memcache in DP

MMMProblems in MMM

Page 19: MMM&Memcache in DP

What's wrong with MMM

MMM is 1) fundamentally broken and unsuitable for use as a HA tool2) absolutely cannot be fixed.

http://www.xaprb.com/blog/2011/05/04/whats-wrong-with-mmm/

Page 20: MMM&Memcache in DP

MMM Problem 1

set read_only is difficult on busy serverset read_only will be blocked by long running SQL

Monitor

Slavevip3

Mastervip1

Slavevip4

Mastervip2set global read_only=1

Page 21: MMM&Memcache in DP

MMM Problem 1

Monitor

Slavevip3

Mastervip1

Slavevip4

Mastervip2set global read_only=1

Page 22: MMM&Memcache in DP

MMM Problem 1 -- Fix

Monitor

Slavevip3

Mastervip1

Slavevip4

Mastervip2remove vip

Page 23: MMM&Memcache in DP

MMM Problem 1 -- Fix

Monitor

Slavevip3

Master

Slavevip4

Mastervip2kill uncommited

process

Page 24: MMM&Memcache in DP

MMM Problem 1 -- Fix

Monitor

Slavevip3

Master

Slavevip4

Mastervip2kill uncommited

process

Page 25: MMM&Memcache in DP

MMM Problem 1 -- Fix

Monitor

Slavevip3

Master

Slavevip4

Mastervip1&vip2

show master statschange master to

Page 26: MMM&Memcache in DP

MMM Problem 2

Monitor

Slave30m Behind

Master

Slavevip4

Mastervip2

select MASTER_POS_WAIT()

Writer VIP cannot be accessed when slave is far behind master

Page 27: MMM&Memcache in DP

MMM Problem 2

Monitor

Slavevip3

Master

Slavevip4

Mastervip1&2

Writer VIP cannot be accessed when slave is far behind master

30 minutes later.......

Page 28: MMM&Memcache in DP

MMM Problem 2 -- Fix

Monitor

Slave30m behind

Master

Slavevip4

Mastervip2

Record the position on M2 and Bring on VIP1 immediately

select MASTER_POS_WAIT

Page 29: MMM&Memcache in DP

MMM Problem 2 -- Fix

Monitor

Slave30m behind

Master

Slavevip4

Mastervip2

Record the position on M2 and Bring up VIP1 immediately

show master status$file $position

Page 30: MMM&Memcache in DP

MMM Problem 2 -- Fix

Monitor

Slave30m behind

Master

Slavevip4

Mastervip1&2

Record the position on M2 and Bring up VIP1 immediately

Bring up VIP1

Page 31: MMM&Memcache in DP

MMM Problem 2 -- Fix

Monitor

Slave30m behind

Master

Slavevip4

Mastervip1&2

Record the position on M2 and Bring up VIP1 immediately

select MASTER_POS_WAIT

Page 32: MMM&Memcache in DP

MMM Problem 2 -- Fix

Monitor

Slave30m behind

Master

Slavevip4

Mastervip1&2

Record the position on M2 and Bring up VIP1 immediately

change master to M2$file $position

Page 33: MMM&Memcache in DP

Memcachedmemcached in DP

Page 34: MMM&Memcache in DP

Memcached in DP

Node1

Node2

Node3

Node3

Main Ring Backup Ring

Page 35: MMM&Memcache in DP

Memcached in DP

Node1

Node2

Node3

Node3

Main Ring Backup Ring

Client

set key1 set key1

Page 36: MMM&Memcache in DP

Memcached in DP

Node1

Node2

Node3

Node3

Main Ring Backup Ring

Client

get key1

Page 37: MMM&Memcache in DP

Memcached in DP

Node1

Node2

Node3

Node3

Main Ring Backup Ring

Client

get key1 get key1

Page 38: MMM&Memcache in DP

MemcachedProblems We Met

Page 39: MMM&Memcache in DP

MultiGet Hole

MultiGet / Gets: get command with multiple keys

Purpose: Omit the multiple network round-trips, when issuing multiple single get commands.

Problem: The gets command will be slower when we add more nodes into the cluster.

Page 40: MMM&Memcache in DP

MultiGet Hole

Node1 Node2 Node3

Client get key1,key2 ... key12

Page 41: MMM&Memcache in DP

MultiGet Hole

Client

<node1> get key1,key4,key7,key10

<node3> get key3,key6,key7,key12

<node2> get key2,key5,key8,key11

Node1 Node2 Node3

Page 42: MMM&Memcache in DP

MultiGet Hole

Node1 Node2 Node3

ClientResultv1,v4,v7,v10

<node3> get key3,key6,key9,key12

<node2> get key2,key5,key8,key11

<node1> get key1,key4,key7,key10

Page 43: MMM&Memcache in DP

MultiGet Hole

Node1 Node2 Node3

Client <node3> get key3,key6,key9,key12

<node2> get key2,key5,key8,key11

Resultv1,v4,v7,v10v2,v5,v8,v11

Page 44: MMM&Memcache in DP

MultiGet Hole

Node1 Node2 Node3

ClientResult

v1,v4,v7,v10v2,v5,v8,v11v3,v6,v9,v12

<node3> get key3,key6,key9,key12

Page 45: MMM&Memcache in DP

MultiGet Hole

Node1 Node2 Node3

Client

One more Round Trip !!!!

Node4

Resultv1,v5,v9

v2,v6,v10v3,v7,v11v4,v8,v12

Page 46: MMM&Memcache in DP

Cache Miss Storm

Happens when : ● Memcached failed● Key expire

Ideal Cache Miss Procedure1. get memcached miss2. query MySQL3. set memcached

Page 47: MMM&Memcache in DP

Cache Miss Storm

In Fact !1. get memcached miss2. massive concurrent query on MySQL

(timeout)3. nothing be set into memcached4. cache miss forever....

Page 48: MMM&Memcache in DP

Cache Miss Storm -- Our Solution

Hot Key0. set local cache after every get1. get memcached miss2. add lock key

a. if (success) query MySQL & set memcacheb. if (failed) return local cache

* Only one web can query MySQL for missed key at the same time.

Page 49: MMM&Memcache in DP

VPL

VPL: virtual packet lossno actual packet loss, but vm response time exceeds the retransmission timeout

Two network-bounded virtual machine put together result in huge get timeout.

Page 50: MMM&Memcache in DP

VPL

A normal retransmission consume 50ms, which exceeds our Memcached timeout. timeout == no result == cache missResult: another kind of cache miss storm

Page 51: MMM&Memcache in DP

Avoid VPL

● Split Network-Bound biz on different real machine.

● Maybe UDP?● Maybe fast retransmission?

Page 52: MMM&Memcache in DP

Thanks!Q&A