Motivation Large-scale distributed application require different forms of coordination: Configuration Group membership and leader election Synchronization.

Slides:



Advertisements
Similar presentations
Paxos and Zookeeper Roy Campbell.
Advertisements

P. Hunt, M Konar, F. Junqueira, B. Reed Presented by David Stein for ECE598YL SP12.
Apache ZooKeeper By Patrick Hunt, Mahadev Konar
Wait-free coordination for Internet-scale systems
HUG – India Meet November 28, 2009 Noida Apache ZooKeeper Aby Abraham.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
Flavio Junqueira, Mahadev Konar, Andrew Kornev, Benjamin Reed
Algorithm Programming Concurrent Programming in Java Bar-Ilan University תשס"ח Moshe Fresko.
Distributed Systems Fall 2010 Replication Fall 20105DV0203 Outline Group communication Fault-tolerant services –Passive and active replication Highly.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
© Amir Kirsh Threads Written by Amir Kirsh. 2 Lesson’s Objectives By the end of this lesson you will: Be familiar with the Java threads syntax and API.
Introduction to Java Programming Language Junji Zhi University of Toronto 1.
Multithreading.
Synchronization Methods for Multicore Programming Brendan Lynch.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
MAHADEV KONAR Apache ZooKeeper. What is ZooKeeper? A highly available, scalable, distributed coordination kernel.
Inter-process Communication and Coordination Chaitanya Sambhara CSC 8320 Advanced Operating Systems.
Oracle10g RAC Service Architecture Overview of Real Application Cluster Ready Services, Nodeapps, and User Defined Services.
Internet Software Development More stuff on Threads Paul Krause.
Object Oriented Programming Lecture 8: Introduction to laboratorial exercise – part II, Introduction to GUI frames in Netbeans, Introduction to threads.
Online Appointment Book Implement a Client/Server application for an online appointment book. Client should be a Graphical User Interface application.
10/17/2015Vimal1 Threads By 10/17/2015Vimal2 Why use threads?? It is a powerful programming tool Computer users take it for granted.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
In the name of Allah The Proxy Pattern Elham moazzen.
7/26/ Design and Implementation of a Simple Totally-Ordered Reliable Multicast Protocol in Java.
Distributed Systems Concepts and Design Chapter 4.
Module 7: Resolving NetBIOS Names by Using Windows Internet Name Service (WINS)
1 Web Based Programming Section 8 James King 12 August 2003.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
Dynamic Architectures (Component Reconfiguration) with Fractal.
2/26/021 Pegasus Security Architecture Author: Nag Boranna Hewlett-Packard Company.
Concurrency in Java Brad Vander Zanden. Processes and Threads Process: A self-contained execution environment Thread: Exists within a process and shares.
FTP Server API Implementing the FTP Server Registering FTP Command Callbacks Data and Control Port Close Callbacks Other Server Calls.
IBM TSpaces Lab 3 Transactions Event Registration.
Threads II IS Outline  Quiz  Thread review  Stopping a thread  java.util.Timer  Swing threads javax.swing.Timer  ProgressMonitor.
Introduction to ZooKeeper. Agenda  What is ZooKeeper (ZK)  What ZK can do  How ZK works  ZK interface  What ZK ensures.
Computer Science 320 A First Program in Parallel Java.
Chapter 4: Threads Joe McCarthy CSS 430: Operating Systems - Threads1.
Data Communication EDA344, DIT420 Description of Lab 1 and Optional Programming HTTP Assignment Bapi Chatterjee Prajith R G.
Zookeeper Wait-Free Coordination for Internet-Scale Systems.
ZOOKEEPER. CONTENTS ZooKeeper Overview ZooKeeper Basics ZooKeeper Architecture Getting Started with ZooKeeper.
VAXclusters: A Closely Coupled Distributed System Landon Cox February 19, 2016.
Apache ZooKeeper CMSC 491 Hadoop-Based Distributed Computing Spring 2016 Adam Shook.
JAFKA A fast MQ. overview ● ● 271KB single jar ● 3.5MB with all dependencies and configurations.
Detour: Distributed Systems Techniques
강호영 Contents ZooKeeper Overview ZooKeeper’s Performance ZooKeeper’s Reliability ZooKeeper’s Architecture Running Replicated ZooKeeper.
Threads in Java Two ways to start a thread
ZooKeeper Claudia Hauff.
Client-server Programming
Apache Zookeeper Hunt, P., Konar, M., Junqueira, F.P. and Reed, B., 2010, June. ZooKeeper: Wait-free Coordination for Internet-scale Systems. In USENIX.
Zookeeper Ken Birman Spring, 2018
Introduction to Apache ZooKeeper™
VAXclusters: A Closely Coupled Distributed System
Replication Middleware for Cloud Based Storage Service
Distributed Systems - Comp 655
File service architecture
Distributed P2P File System
Condition Variables and Producer/Consumer
CNT 4007C Project 2 Good morning, everyone. In this class, we will have a brief look at the project 2. Project 2 is basically the same with project 1.
Condition Variables and Producer/Consumer
Wait-free coordination for Internet-scale systems
class PrintOnetoTen { public static void main(String args[]) {
Threads and Multithreading
Overview Multimedia: The Role of WINS in the Network Infrastructure
Distributed Dynamic Channel Allocation in Wireless Network
ZooKeeper Justin Magnotti 9/19/18.
CMSC 202 Threads.
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Message Passing Systems
Pig Hive HBase Zookeeper
Presentation transcript:

ZooKeeper: A Distributed Coordination Service for Distributed Applications

Motivation Large-scale distributed application require different forms of coordination: Configuration Group membership and leader election Synchronization Configuration: a list of operational parameters for the system processes Group membership: often processes need to know which other processes are alive and what those processes are in charge of

Related Works Amazon Simple Queue Service-queuing [25]-leader election [27]-configuration Chubby[6]-locking service with strong synchronization

Zookeeper Zookeeper is a distributed service for distributed applications. It support: Synchronization Configuration management Naming service

Why Do We Need Zookeeper Zookeeper is simple Zookeeper is replicated Zookeeper is ordered Zookeeper is fast

Data Model Regular Znode Ephemeral Znode Sequential flag

Watches Zookeeper Client1 Client4 create/exist/(WATCH) NOTIFICATION setData Client1 Client4

Client API create(path, data, flags) delete(path, version) exists(path, watch) getData(path, watch) setData(path, data, version) getChildren(path, watch) sync(path)

Zookeeper Service Architecture Read request is handled by local server Write request is sent to the leader, the leader broadcasts the change to the Zookeeper through Zab an atomic broadcast protocol.

Setup Zookeeper Download: http://www.apache.org/dyn/closer.cgi/zookeeper/ Configure Zookeeper: Standalone Mode Replicated Mode tickTime: the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime. dataDir: the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database. clientPort: the port to listen for client connections

Standalone Mode create file zoo.cfg with the content: Start server: bin/zkServer.sh start Test with zookeeper client: bin/zkCli.sh -server 127.0.0.1:2181 tickTime=2000 dataDir=/var/lib/zookeeper clientPort=2181

Standalone Mode (2) ls / get Set …

Setup Zookeeper: Replicated mode Every server has the same configuration file. Create file named myid In the datadir directory. The content of myid file is an unique number. tickTime=2000 dataDir=/home/sdn/zookeeper clientPort=2181 initLimit=5 syncLimit=2 server.1=192.168.0.94:2888:3888 server.2=192.168.0.59:2888:3888 … server.n=192.168.0.59:2888:3888

Use cases Naming service Configuration management Synchronization Message Queue Notification system

Synchronization: Simple Lock Client has smallest number have permission to access locked object When the client finishes work with object, child node is deleted. Another client has smallest number have permission to access locked object AppRoot P(n) P(n+1) P(n+2) P(n+3) Zookeeper N=create(P, EPHEMERAL|SEQUENTIAL) N=create(P, EPHEMERAL|SEQUENTIAL) N=create(P, EPHEMERAL|SEQUENTIAL) N=create(P, EPHEMERAL|SEQUENTIAL) Client1 Client4 Client2 Client3

Synchronization: Simple Lock Check existing of approot and create it. Create child node with Sequential and Ephemeral flag And receive a number. When receive the notification, check whether the number is smallest of child nodes number

Synchronization: Barrier public class SimpleLock implements Watcher ZooKeeper zooKeeper = new ZooKeeper("192.168.0.94:2181", 3000, this); Stat res = zooKeeper.exists(root, true); if(res==null) String abc = zooKeeper.create(root, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); String createRes = zooKeeper.create(root+"/", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL); int number = Integer.parseInt(createRes.substring(root.length()+1)); while (true) { synchronized (root) { //TODO check whether the number is smallest if(smallest) {dost();}else{root.wait();} }} public void process(WatchedEvent event) { //Watcher event synchronized (root) {root.notify();} } private void dost(){ System.out.println("Access System.out at "+System.currentTimeMillis()); Thread.sleep(5000); }

Synchronization: Simple Lock public static void main(String[] args){ new SimpleLock(); } /simpleLock/0000000009:9 Access System.out at 1416028020742 /simpleLock/0000000010:10 Access System.out at 1416028025765 /simpleLock/0000000011:11 Access System.out at 1416028030779 /simpleLock/0000000012:12 Access System.out at 1416028035806

Synchronization: Barrier Every client creates child node of approot. Whenever the number of child nodes is enough, client will start work. AppRoot P(n) P(n+1) P(n+2) P(n+3) Zookeeper N=create(P, EPHEMERAL|SEQUENTIAL) N=create(P, EPHEMERAL|SEQUENTIAL) N=create(P, EPHEMERAL|SEQUENTIAL) N=create(P, EPHEMERAL|SEQUENTIAL) Client1 Client4 Client2 Client3

Synchronization: Barrier Check existing of approot and create it. Create child node with Sequential and Ephemeral flag And receive a number. When receive the notification, check whether the number is smallest of child nodes number

Synchronization: Barrier public static void main(String[] args){ new Barrier(3).run();} Run 3 instances: /barrier/0000000022 Starting at 1416048008944 /barrier/0000000023 Starting at 1416048008947 /barrier/0000000024 Starting at 1416048008948

N=create(P, SEQUENTIAL) N=create(P, SEQUENTIAL) Message Queue Every client creates child node of approot. Whenever the number of child nodes is enough, client will start work. AppRoot P(n) P(n+1) P(n+2) P(n+3) N=create(P, SEQUENTIAL) sender1 get(smallestP) Zookeeper receiver N=create(P, SEQUENTIAL) sender2

Message Queue public class MessageQueue implements Watcher public static class Sender extends MessageQueue implements Runnable public static class Receiver extends MessageQueue implements Runnable public void sendMessage() { //Watcher event String sendMessage = "sendMessage at "+System.currentTimeMillis(); zooKeeper.create(root+"/", sendMessage.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); } while (true) { synchronized (root) { List<String> childs = zooKeeper.getChildren(root, true); if(childs.size()==0){root.wait();}else{ //TODO sort the list for (String child : childs) { byte[] data = zooKeeper.getData(root+"/"+child, false, new Stat()); System.out.println("readMessage:"+new String(data)); zooKeeper.delete(root+"/"+child, 0); } } }} public void process(WatchedEvent event) { //Watcher event synchronized (root) {root.notify();} }

Message Queue: Run 2 sender instances and 1 receiver instance: readMessage:sendMessage at 1416066118908 readMessage:sendMessage at 1416066118916 readMessage:sendMessage at 1416066118926 readMessage:sendMessage at 1416066118929 readMessage:sendMessage at 1416066118939 readMessage:sendMessage at 1416066118942 readMessage:sendMessage at 1416066118952 readMessage:sendMessage at 1416066118954 readMessage:sendMessage at 1416066118964 readMessage:sendMessage at 1416066118967 readMessage:sendMessage at 1416066118976 readMessage:sendMessage at 1416066118984 readMessage:sendMessage at 1416066118989 readMessage:sendMessage at 1416066118997 readMessage:sendMessage at 1416066119001 readMessage:sendMessage at 1416066119009 readMessage:sendMessage at 1416066119016