java.util.concurrent for distributed coordination Ensar Basri - - PowerPoint PPT Presentation

java util concurrent for distributed coordination
SMART_READER_LITE
LIVE PREVIEW

java.util.concurrent for distributed coordination Ensar Basri - - PowerPoint PPT Presentation

java.util.concurrent for distributed coordination Ensar Basri Kahveci Hazelcast @metanet Hazelcast The leading open source Java IMDG Distributed Java collections, concurrency primitives, messaging Caching, application scaling, distributed


slide-1
SLIDE 1

java.util.concurrent for distributed coordination

Ensar Basri Kahveci Hazelcast

slide-2
SLIDE 2

@metanet

Hazelcast

The leading open source Java IMDG Distributed Java collections, concurrency primitives, messaging Caching, application scaling, distributed coordination 🎊 Hazelcast Cloud https://hazelcast.cloud Hazelcast Jet: In-memory stream and fast batch processing

slide-3
SLIDE 3

@metanet

Agenda

What is distributed coordination? How distributed coordination APIs evolved over time? java.util.concurrent.* for distributed coordination Demo on Hazelcast IMDG 3.12

slide-4
SLIDE 4

#

slide-5
SLIDE 5

@metanet

Distributed Coordination

Leader election Synchronization Group membership Configuration and metadata management

slide-6
SLIDE 6

DO IT YOURSELF

slide-7
SLIDE 7

@metanet

Consensus algorithms under the hood CP with respect to CAP Deployed as a central repository APIs for coordination tasks

Distributed Coordination Systems

slide-8
SLIDE 8

Google Chubby (Paxos)

@metanet

slide-9
SLIDE 9

Google Chubby (Paxos) Apache ZooKeeper (ZAB)

@metanet

slide-10
SLIDE 10

Google Chubby (Paxos) Apache ZooKeeper (ZAB) etcd (Raft)

@metanet

slide-11
SLIDE 11

@metanet

/services /payment /product /photo /services /services/payment /services/product /services/product/photo

Chubby & ZooKeeper etcd

slide-12
SLIDE 12

@metanet

Chubby

Locking APIs Recipes

ZooKeeper etcd

slide-13
SLIDE 13

@metanet

A Simple Locking Recipe for ZooKeeper

  • 1. create an ephemeral znode “/lock”
  • 2. if success, enter to the critical section
  • 3. else, register a watch on “/lock”
  • 4. when the watch is notified, i.e., the lock is released, retry step #1
slide-14
SLIDE 14

@metanet

Chubby

Locking APIs Recipes “Friends don't let friends write ZK recipes.” Apache Curator Tech Notes #6 Leader election and distributed lock primitives

ZooKeeper etcd

slide-15
SLIDE 15

@metanet

High-level APIs

A low-level file-system / KV store API is

  • easy to misuse,
  • not suitable for all coordination tasks.

High-level APIs minimise guesswork and development effort. java.util.concurrent.* in JDK

slide-16
SLIDE 16

Concurrency Nondeterminism Distributed applications Multithreaded applications Partial failures

slide-17
SLIDE 17

Google Chubby (Paxos) Apache ZooKeeper (ZAB) etcd (Raft) Hazelcast IMDG 3.12

java.util.concurrent

  • n top of Raft

@metanet

slide-18
SLIDE 18

@metanet

An Opinionated & High-Level Framework

IAtomicLong, IAtomicReference, ICountDownLatch, ISemaphore, FencedLock Well-defined failure semantics CP with respect to CAP DIY-style tested with Jepsen

slide-19
SLIDE 19

@metanet

Understandability as a primary goal Handles crash failures and network failures. Operational as long as the majority is up. Runtime concerns (snapshotting, dynamic membership) Performance optimizations (fast reads, batching) https://raft.github.io

Why Raft?

slide-20
SLIDE 20

@metanet

A leader is elected among the nodes. The leader replicates ops to the followers. All nodes run the ops in the same order.

Replicated State Machines

slide-21
SLIDE 21

@metanet

CP Subsystem

Minimal configuration CP primitives and AP data structures in the same cluster Dynamic clustering programmatically or via REST API

slide-22
SLIDE 22

@metanet

Horizontal Scalability

Each CP group runs the Raft algorithm independently. CP primitives can be distributed to multiple CP groups. CP groups can be distributed to CP members.

slide-23
SLIDE 23

@metanet

ENOUGH TALK LET’S DEMO

slide-24
SLIDE 24

@metanet

https://github.com/metanet/juc-talk

DEMO #1: Configuration management

slide-25
SLIDE 25

@metanet

FencedLock

Linearizable distributed impl of java.util.concurrent.locks.Lock Suitable for both fine-grained and coarse-grained locking

slide-26
SLIDE 26

@metanet

CP Sessions

A session starts on the first lock / semaphore request. Session heartbeats are periodically committed in the background. If no heartbeat for some time (session TTL), the session is closed. Auto-release mechanism for FencedLock and ISemaphore

slide-27
SLIDE 27

@metanet

DEMO #2: Adding Redundancy

We use FencedLock for leader election.

slide-28
SLIDE 28

@metanet

CP sessions offer a trade-off between safety and liveness.

slide-29
SLIDE 29

@metanet

DEMO #3: Fencing-off Stale Lock Holders

“How to do distributed locking” “Distributed locks are dead; long live distributed locks!”

slide-30
SLIDE 30

@metanet

Recap

Avoid writing your own implementations for coordination. High-level APIs minimise guesswork and development effort. java.util.concurrent.* FTW! Operational simplicity matters. Dynamic clustering Horizontal scalability

slide-31
SLIDE 31

@metanet

Future Plans

KV Store Event Listeners Disk persistence Tooling

slide-32
SLIDE 32

@metanet

Resources

https://github.com/metanet/juc-talk (demos) Hazelcast IMDG Docs CP Subsystem Code Samples https://hazelcast.com/blog/author/ensarbasri Hazelcast IMDG 3.12

slide-33
SLIDE 33

Thanks!

In-Memory Computing Summit Europe 2019 Ensar Basri Kahveci

Distributed Systems Engineer @ Hazelcast @ metanet