java.util.concurrent
for distributed coordination
Devoxx Ukraine 2019
Ensar Basri Kahveci
Distributed Systems Engineer @ Hazelcast
@ metanet
@metanet
Hazelcast
The leading open source Java IMDG
Distributed Java collections, concurrency primitives, messaging
Caching, application scaling, distributed coordination 🎉
Hazelcast Cloud
https://hazelcast.cloud
#devoxxua2019
@metanet
Agenda
What is distributed coordination?
How distributed coordination APIs evolved over time?
Why to use java.util.concurrent.*
Demo on Hazelcast IMDG 3.12
#devoxxua2019
#DevoxxUA
@metanet
Distributed Coordination
Leader election
Synchronization
Service discovery
Configuration management for microservices
#devoxxua2019
@metanet
Challenges
Concurrency problems
Partial failures in distributed systems
Consistency issues
#devoxxua2019
DO IT
YOURSELF
@metanet
Consensus algorithms under the hood
CP with respect to CAP
Deployed as a central service
APIs for coordination tasks
Distributed Coordination Systems
#devoxxua2019
@metanet
Distributed Coordination Systems
Google Chubby (Paxos)
Apache ZooKeeper (ZAB)
etcd (Raft)
#devoxxua2019
@metanet
APIs for Coordination: Layer #1
Some form of KV store API
Suitable for configuration management and service discovery
Foundational layer for building higher-level APIs
/services
/payment
/product
/photo
/services
/services/payment
/services/product
/services/product/photo
Chubby & ZooKeeper etcd
#devoxxua2019
@metanet
APIs for Coordination: Layer #2
Chubby: Locking APIs on files
ZooKeeper: Recipes
Algorithms to build high-level primitives on top its FS
“Friends don't let friends write ZK recipes.” Apache Curator Tech Notes #6
etcd: Leader election and distributed lock primitives on top of its KV store
#devoxxua2019
@metanet
Need for High-level APIs
KV-store / low-level file-system API is
easy to misuse,
not suitable for all coordination tasks.
“Consensus in the Cloud: Paxos Systems Demystified”
High-level APIs minimise guesswork and development effort.
java.util.concurrent.* in JDK
#devoxxua2019
@metanet
Distributed Coordination Systems
Google Chubby (Paxos)
Apache ZooKeeper (ZAB)
etcd (Raft)
Hazelcast IMDG 3.12 CP Subsystem (Raft)
#devoxxua2019
@metanet
Hazelcast IMDG 3.12 CP Subsystem
IAtomicReference
Configuration and metadata management for basic use-cases
IAtomicLong, ICountDownLatch, ISemaphore
Distributed synchronization
FencedLock
Distributed locking and leader election
#devoxxua2019
@metanet
Hazelcast IMDG 3.12 CP Subsystem
Well-defined failure semantics
Strong consistency
CP with respect to CAP
DIY-style tested with Jepsen
#devoxxua2019
@metanet
Strong consistency
Handles crashes and network failures.
Operational as long as the majority is up.
Consensus
Node
Count
Majority Degree of
Fault Tolerance
2 2 0
3 2 1
4 3 1
5 3 2
6 4 2
7 4 3
#devoxxua2019
@metanet
Understandability as the primary goal
Runtime concerns (snapshotting, dynamic membership)
Performance optimizations (fast reads, batching)
https://raft.github.io
Why Raft?
#devoxxua2019
@metanet
ENOUGH TALK
LET’S DEMO
@metanet
https://github.com/metanet/juc-talk
DEMO #1: Leader Election
#devoxxua2019
@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
#devoxxua2019
@metanet
CP sessions offer a trade-off between safety and liveness.
#devoxxua2019
@metanet
“How to do distributed locking”
“Distributed locks are dead; long live distributed locks!”
DEMO #2: Fencing-off Stale Lock Holders
#devoxxua2019
@metanet
Replacing crashed CP members to preserve high availability
Demo #3: Handling Server Failures
#devoxxua2019
@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
#devoxxua2019
@metanet
Current Status
In Hazelcast 4.0:
CP Subsystem disk persistence
Metrics
In roadmap:
KV Store
Event Listeners
More client languages
#devoxxua2019
@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
#devoxxua2019
Дякую!
Devoxx Ukraine 2019
#DevoxxUA
Ensar Basri Kahveci
Distributed Systems Engineer @ Hazelcast
@ metanet

java.util.concurrent for Distributed Coordination - Devoxx Ukraine 2019