Top Banner
June 29, 2013 Taming Pythons with ZooKeeper Wednesday, 3 July 13
40

Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Jan 14, 2020

Download

Documents

dariahiddleston
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: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

June 29, 2013

Taming Pythons with ZooKeeper

Wednesday, 3 July 13

Page 2: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

$ whoami

Wednesday, 3 July 13

Page 3: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Jyrki Pulliainen

@[email protected]

Wednesday, 3 July 13

Page 4: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Wednesday, 3 July 13

Page 5: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

ZooKeeper?

Wednesday, 3 July 13

- This talk is about ZooKeeper.- Preaching Java software in Python conference. I can think of more healthier things to do too.

- On side note, our Product Owner is really damn good at this game

Page 6: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

ZooKeeper!

Wednesday, 3 July 13

- Apache project, Yahoo 2007- Consistency & Partition tolerance- Filesystem like, actually can be viewed as a trie, store data in directories too- In memory, limits the dataset you can store. Maximum zookeeper node, znode, data size 1M

Page 7: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

The Tao of ZooKeeper

7

Wednesday, 3 July 13

Orderly, Reliable, Efficient, Timely, Contention free, ambition free

Page 8: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Wednesday, 3 July 13

Page 9: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

June 29, 2013

One library for the enterpriseCurator, from Netflix

Wednesday, 3 July 13

Page 10: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

June 29, 2013

Seven for the pythonistasgevent-zookeeperzkpythonzc.zkpykeeper

twitter’s zookeeper libraryzooptxzookeeper

Wednesday, 3 July 13

- gevent-zookeeper -> Spotify- zkpython segfaults- Others have somewhat OK implementations, but lack core features

Page 11: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

One Library to rule them all*

* unless you are running twisted

Wednesday, 3 July 13

- txzookeeper still valid for twisted

Page 12: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Kazoo

Wednesday, 3 July 13

- Origins from the Nimbus project- Ben Bangert as the Sauron of ZooKeeper- Not Frodo, that bastard wanted to destroy the perfectly good ring.- All Python, including the protocol. No more segfaults!

Page 13: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

CRUD

ZooKeeper CRUD

Let’s talk about KaZoo

13

Wednesday, 3 July 13

Create, Read, Update, DeleteAll basic operations available as async too, but we’ll focus on the synchronous use

Page 14: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

First we need to connect!

Text

from kazoo.client import KazooClient

zk = KazooClient(hosts='127.0.0.1:2181')zk.start()# ...zk.stop()

TextText

Wednesday, 3 July 13

Easy to connect to one host, multiple host, with namespace....ZooKeeper supports connection namespacing!Bonus: get notified when the connection state changes

Page 15: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

First we need to connect!

Text

from kazoo.client import KazooClient

zk = KazooClient(hosts='127.0.0.1:2181')zk.start()# ...zk.stop()

TextTextzk = KazooClient(hosts='127.0.0.1:2181,127.0.0.2:2181')

Wednesday, 3 July 13

Easy to connect to one host, multiple host, with namespace....ZooKeeper supports connection namespacing!Bonus: get notified when the connection state changes

Page 16: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

First we need to connect!

Text

from kazoo.client import KazooClient

zk = KazooClient(hosts='127.0.0.1:2181')zk.start()# ...zk.stop()

Text

zk = KazooClient(hosts='127.0.0.1:2181/namespace,127.0.0.2:2181')

Textzk = KazooClient(hosts='127.0.0.1:2181,127.0.0.2:2181')

Wednesday, 3 July 13

Easy to connect to one host, multiple host, with namespace....ZooKeeper supports connection namespacing!Bonus: get notified when the connection state changes

Page 17: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Create

zk.create('/europython', b'2013')

Wednesday, 3 July 13

Adding nodes easy, helpers exist for recursive creationEphemeral ZK feature, session + heartbeats, can’t have children!Incremental: guaranteed ever increasing 10 digit number in node name

Page 18: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Create

zk.create('/europython', b'2013')

zk.create('/europython/jyrki', ephemeral=True)

Wednesday, 3 July 13

Adding nodes easy, helpers exist for recursive creationEphemeral ZK feature, session + heartbeats, can’t have children!Incremental: guaranteed ever increasing 10 digit number in node name

Page 19: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Create

zk.create('/europython', b'2013')

zk.create('/europython/jyrki', ephemeral=True)

zk.create('/europython/sequential', sequence=True)

Wednesday, 3 July 13

Adding nodes easy, helpers exist for recursive creationEphemeral ZK feature, session + heartbeats, can’t have children!Incremental: guaranteed ever increasing 10 digit number in node name

Page 20: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Read

Text

zk.get('/europython')

Wednesday, 3 July 13

Page 21: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Read

Text

zk.get('/europython')

zk.exists('/europython/jyrki')

Wednesday, 3 July 13

Page 22: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Read

Text

zk.get('/europython')

zk.exists('/europython/jyrki')

zk.get_children('/europython')

Wednesday, 3 July 13

Page 23: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Update & Delete

zk.set_data('/europython/jyrki', b'nervous')

Wednesday, 3 July 13

Page 24: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Update & Delete

zk.set_data('/europython/jyrki', b'nervous')

zk.delete('/europython/jyrki')

Wednesday, 3 July 13

Page 25: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Wednesday, 3 July 13

Page 26: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Distributed locks?

Barrier?

Semaphores?

Counters?

Elections?

Wednesday, 3 July 13

Page 27: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Textfrom kazoo.recipe import <your-favourite-thing>

Wednesday, 3 July 13

Of course it does not have everything from curator

Page 28: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Want to know when things change?

Wednesday, 3 July 13

Page 29: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

watchers

Wednesday, 3 July 13

Page 30: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Text

zk.exists('/europython/wine', watch=callback)

zk.get('/europython/wine', watch=callback)

zk.get_children('/europython/dinners', watch=callback)

Wednesday, 3 July 13

Page 31: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

from kazoo.recipe.watchers import DataWatch, ChildWatch

@DataWatch('/path/to/node')def data_callback(data, stat): # ... do_something

@ChildWatch('/path/to/node')def child_callback(children): # ... do_something

Wednesday, 3 July 13

Page 32: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

TESTS

Wednesday, 3 July 13

Page 33: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

What if something goes

WRONG?

Wednesday, 3 July 13

Page 34: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

sys.exit()Wednesday, 3 July 13

Page 35: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Stand back!

It’s time for real life example

Wednesday, 3 July 13

Page 36: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Wednesday, 3 July 13

Page 37: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

SEARCHED FOR THE NEWEST JUSTIN BIEBER

Encryption keys were not available to play it.

Wednesday, 3 July 13

Page 38: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

SUMMARY

Wednesday, 3 July 13

Page 39: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Guess what, we’re hiring

Wednesday, 3 July 13

Page 40: Taming Pythons with ZooKeeper · Taming Pythons with ZooKeeper Wednesday, 3 July 13 $ whoami Wednesday, 3 July 13. Jyrki Pulliainen @nailor ... - Consistency & Partition tolerance

Thank You!

[email protected]

@nailor

Wednesday, 3 July 13