Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \:...

68
Cluster Consensus When Aeron Met Raft Martin Thompson - @mjpt777

Transcript of Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \:...

Page 1: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Cluster Consensus

When Aeron Met Raft

Martin Thompson - @mjpt777

Page 2: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

What does “Consensus” mean?

Page 3: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

con•sen•susnoun \ kən-ˈsen(t)-səs \

: general agreement : unanimity

Source: http://www.merriam-webster.com/

Page 4: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

con•sen•susnoun \ kən-ˈsen(t)-səs \

: general agreement : unanimity

: the judgment arrived at by most of those

concerned

Source: http://www.merriam-webster.com/

Page 5: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

https://raft.github.io/raft.pdf

Page 6: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

https://www.cl.cam.ac.uk/~ms705/pub/papers/2015-osr-raft.pdf

Page 7: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Raft in a Nutshell

Page 8: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Roles

CandidateFollower Leader

Page 9: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

RPCs

1. RequestVote RPCInvoked by candidates to gather votes

2. AppendEntries RPCInvoked by leader to replicate and heartbeat

Page 10: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Safety Guarantees

• Election Safety

• Leader Append-Only

• Log Matching

• Leader Completeness

• State Machine Safety

Page 11: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Monotonic Functions

Page 12: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Version all the things!

Page 13: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Clustering Aeron

Page 14: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Is it Guaranteed Delivery™ ???

Page 15: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

What is the “Architect” really looking for?

Page 16: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Replicated State Machines

=>

Redundant Deterministic Services

Page 17: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Client Client Client Client Client

Service

Page 18: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Client Client Client Client Client

Service

Page 19: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Client Client Client Client Client

Consensus

Module

Service

Consensus

Module

Service

Consensus

Module

Service

Page 20: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

NIO Pain

Page 21: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

FileChannel channel = null;

try

{

channel = FileChannel.open(directory.toPath());

}

catch (final IOException ignore)

{

}

if (null != channel)

{

channel.force(true);

}

Page 22: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Directory Sync

Files.force(directory.toPath(), true);

Page 23: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Performance

Page 24: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Let’s consider the application of

an RPC design approach

Page 25: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Client Client Client Client Client

Consensus

Module

Service

Consensus

Module

Service

Consensus

Module

Service

Page 26: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Should we consider

concurrency and parallelism

with Replicated State Machines?

Page 27: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

“Concurrency is about dealing with lots of

things at once. Parallelism is about doing

lots of things at once.”

– Rob Pike

Page 28: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

1. Parallel is the opposite of Serial

2. Concurrent is the opposite of Sequential

3. Vector is the opposite of Scalar

– John Gustafson

Page 29: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Fetch

Time

Instruction Pipelining

Page 30: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Fetch Decode

Time

Instruction Pipelining

Page 31: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Fetch Decode Execute

Time

Instruction Pipelining

Page 32: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Fetch Decode Execute Retire

Time

Instruction Pipelining

Page 33: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Fetch Decode Execute Retire

Time

Fetch Decode Execute Retire

Instruction Pipelining

Page 34: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Fetch Decode Execute Retire

Time

Fetch Decode Execute Retire

Fetch Decode Execute Retire

Instruction Pipelining

Page 35: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Fetch Decode Execute Retire

Time

Fetch Decode Execute Retire

Fetch Decode Execute Retire

Fetch Decode Execute Retire

Instruction Pipelining

Page 36: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Order

Time

Consensus Pipeline

Page 37: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Order Log

Time

Consensus Pipeline

Page 38: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Order Log Transmit

Time

Consensus Pipeline

Page 39: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Order Log Transmit Commit

Time

Consensus Pipeline

Page 40: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Order Log Transmit Commit

Time

Consensus Pipeline

Execute

Page 41: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Order Log Transmit Commit

Time

Consensus Pipeline

Execute

Order Log Transmit Commit Execute

Page 42: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Order Log Transmit Commit

Time

Consensus Pipeline

Execute

Order Log Transmit Commit Execute

Order Log Transmit Commit Execute

Page 43: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Client Client Client Client Client

Consensus

Module

Service

Consensus

Module

Service

Consensus

Module

Service

Page 44: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Client Client Client Client Client

Consensus

Module

Service

Consensus

Module

Service

Consensus

Module

Service

Page 45: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

NIO Pain

Page 46: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

ByteBuffer byte[] copies

ByteBuffer byteBuffer = ByteBuffer.allocate(64 * 1024);

byteBuffer.putInt(index, value);

Page 47: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

ByteBuffer byte[] copies

ByteBuffer byteBuffer = ByteBuffer.allocate(64 * 1024);

byteBuffer.putBytes(index, bytes);

Page 48: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

ByteBuffer byte[] copies

ByteBuffer byteBuffer = ByteBuffer.allocate(64 * 1024);

byteBuffer.putBytes(index, bytes);

Page 49: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

How can Aeron help?

Page 50: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Message Index => Byte Index

Page 51: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Multicast, MDC, and Spy

based Messaging

Page 52: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Counters and Bounded

Consumption

Page 53: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Binary Protocols &

Zero intermediate copies

Page 54: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

0%

10%

20%

30%

40%

50%

60%

70%

80%

90%

100%

0 5 10 15 20

Batching – Amortising Costs

Average overhead

per item or operation

in batch

Page 55: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

0%

10%

20%

30%

40%

50%

60%

70%

80%

90%

100%

0 5 10 15 20

Batching – Amortising Costs

• System calls

• Network round trips

• Disk writes

• Expensive calculations

Page 56: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Interesting Features

Page 57: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Agents and Threads

Page 58: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Timers

Page 59: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Back Pressure and Stashed Work

Page 60: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Replay and Snapshots

Page 61: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Multiple Services on the

same stream

Page 62: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Client Client Client Client Client

Consensus

Module

Service

Consensus

Module

Service

Consensus

Module

Service

Page 63: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

Client Client Client Client Client

Consensus

Module

Service

Consensus

Module

Service

Consensus

Module

ServiceService

ServiceService

ServiceService

Service

Page 64: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

In Closing

Page 65: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

NIO Pain

Page 66: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

DirectByteBuffer MappedByteBuffer

MappedByteBuffer DirectByteBuffer

Page 67: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:
Page 68: Cluster Consensus When Aeron Met Raft - QCon …...con•sen•sus noun \ kən-ˈsen(t)-səs \: general agreement : unanimity: the judgment arrived at by most of those concerned Source:

https://github.com/real-logic/aeron

Twitter: @mjpt777

“A distributed system is one in which the failure of a computer you didn't even know existedcan render your own computer unusable.”

- Leslie Lamport

Questions?