Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Configuration provisioning with Apache Zookeeper
Search
Mariusz Gil
May 20, 2013
Programming
1.1k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Configuration provisioning with Apache Zookeeper
Mariusz Gil
May 20, 2013
More Decks by Mariusz Gil
See All by Mariusz Gil
Aspect Oriented Programming
mariuszgil
1
340
Designing and implementing GraphQL API
mariuszgil
1
110
Discovering unknown with EventStorming ConFoo
mariuszgil
0
320
Game of Developer Life... Deconstructed
mariuszgil
1
200
Back to forgotten roots
mariuszgil
1
430
Go micro with microservices
mariuszgil
5
710
Machine Learning for the rescue
mariuszgil
0
450
Discovering graph structures
mariuszgil
3
560
Introduction to Aerospike with PHP
mariuszgil
8
870
Other Decks in Programming
See All in Programming
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
310
Lessons from Spec-Driven Development
simas
PRO
0
190
3Dシーンの圧縮
fadis
1
770
ふつうのFeature Flag実践入門
irof
7
3.9k
CSC307 Lecture 17
javiergs
PRO
0
320
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
2
670
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.9k
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
540
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.1k
Featured
See All Featured
The agentic SEO stack - context over prompts
schlessera
0
820
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
Chasing Engaging Ingredients in Design
codingconduct
0
220
Amusing Abliteration
ianozsvald
1
200
Crafting Experiences
bethany
1
180
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Transcript
Zookeeper CONFIGURATION PROVISIONING WITH... mariusz gil
About me
None
None
Coordination service for distributed applications and systems
/app/feat_3 /app/f_2 /app/f_1 /servers /app In-memory file system model /
clients zookeeper cluster leader
7use cases name service configuration group membership leader election barriers
queues locks
many projects Apache Accumulo Apache Hadoop MapReduce Apache HBase Apache
Hedwig Apache Kafka Apache S4 Apache Solr Apache Storm Mesos Neo4J
ZooKeeper usage
Installation wget http://ftp.ps.pl/pub/apache/zookeeper/stable/zookeeper-3.4.5.tar.gz touch conf/zoo.cfg vim conf/zoo.cfg # STANDALONE ENVIRONMENT
# tickTime=2000 # dataDir=/var/zookeeper # clientPort=2181 # DISTRIBUTED ENVIRONMENT # tickTime=2000 # dataDir=/var/zookeeper # clientPort=2181 # initLimit=5 # syncLimit=2 # server.1=zoo1:2888:3888 # server.2=zoo2:2888:3888 # server.3=zoo3:2888:3888 bin/zkServer.sh start
CLI mode bin/zkServer.sh start bin/zkCli.sh 127.0.0.1:2181 [zk: localhost:2181(CONNECTED) 31] help
ZooKeeper -server host:port cmd args connect host:port get path [watch] ls path [watch] set path data [version] rmr path delquota [-n|-b] path quit printwatches on|off create [-s] [-e] path data acl stat path [watch] close ls2 path [watch] history listquota path setAcl path acl getAcl path sync path redo cmdno addauth scheme auth delete path [version]
CLI mode bin/zkServer.sh start bin/zkCli.sh 127.0.0.1:2181 [zk: localhost:2181(CONNECTED) 8] ls
/ [zookeeper] ... [zk: localhost:2181(CONNECTED) 17] create /app/features/pymk '' Created /app/features/pymk [zk: localhost:2181(CONNECTED) 20] create /app/features/pymk/enabled 0 Created /app/features/pymk/enabled [zk: localhost:2181(CONNECTED) 24] set /app/features/pymk/enabled 1 [zk: localhost:2181(CONNECTED) 28] get /app/features/pymk/enabled 1 [zk: localhost:2181(CONNECTED) 26] ls /app/features [pymk, login, friends, messages] [zk: localhost:2181(CONNECTED) 29] rmr /app/features [zk: localhost:2181(CONNECTED) 30] ls /app [] bin/zkServer.sh stop
PHP + ZooKeeper
Edit config.prod.yml file Commit to repo Wait for CI report
Build app package Deploy to production
ZooKeeper cluster Web workers Tasks workers
None
$ cd $ git clone https://github.com/andreiz/php-zookeeper.git $ cd php-zookeeper $
phpize $ ./configure $ make $ sudo make install Installation of PHP extensions
<?php class Zookeeper_Example { // ... /** * Set a
node to a value. */ public function set($path, $value) { if (!$this->zookeeper->exists($path)) { $this->makePath($path); $this->makeNode($path, $value); } else { $this->zookeeper->set($path, $value); } } /** * Equivalent of "mkdir -p" on ZooKeeper */ public function makePath($path, $value = '') { $parts = explode('/', $path); $parts = array_filter($parts); $subpath = ''; while (count($parts) > 1) { $subpath .= '/' . array_shift($parts); if (!$this->zookeeper->exists($subpath)) { $this->makeNode($subpath, $value); } } } Example 1 Simple configuration client <?php $zk = new Zookeeper_Example('localhost:2181'); var_dump($zk->get('/')); var_dump($zk->getChildren('/')); var_dump($zk->set('/test123', 'abc')); var_dump($zk->get('/test123')); var_dump($zk->getChildren('/')); var_dump($zk->set('/foo/001', 'bar1')); var_dump($zk->set('/foo/002', 'bar2')); var_dump($zk->getChildren('/foo')); Tekst
<?php class ZookeeperDemo extends Zookeeper { /** * Watcher method
*/ public function watcher( $i, $type, $key ) { echo "Insider Watcher / "; echo "New value for $key is " . $this->get( '/test', array($this, 'watcher' ) ) . "\n"; } } $zoo = new ZookeeperDemo('localhost:2181'); $zoo->get( '/test', array($zoo, 'watcher' ) ); while( true ) { echo '.'; sleep(2); } Example 2 Key change watcher
<?php class Worker extends Zookeeper { const CONTAINER = '/cluster';
protected $acl = array( array( 'perms' => Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone' ) ); private $isLeader = false; private $znode; public function __construct( $host = '', $watcher_cb = null, $recv_timeout = 10000 ) { parent::__construct( $host, $watcher_cb, $recv_timeout ); } public function register() { if( ! $this->exists( self::CONTAINER ) ) { $this->create( self::CONTAINER, null, $this->acl ); } $this->znode = $this->create( self::CONTAINER . '/w-', null, $this->acl, Zookeeper::EPHEMERAL | Zookeeper::SEQUENCE ); $this->znode = str_replace( self::CONTAINER .'/', '', $this->znode ); Example 3 Multiple workers with automatic leader election # console 1 $ php example_worker.php I'm registred as: w-0000000001 Nobody here, I'm the leader Leading # console 2 $ php example_worker.php I'm registred as: w-0000000002 I'm watching w-0000000001 Working # console 3 $ php example_worker.php I'm registred as: w-0000000003 I'm watching w-0000000002 Working
DevOp life?
OMG! I have to disable feature X for a while
and change database schema, but the rest of the app should works... set /app/feature/pymk/enabled 0 ALTER TABLE... set /app/feature/pymk/enabled 1
OMG! I have to add more cache instances and distribute
traffic across many servers set /servers/cache/c6/host 192... set /servers/cache/c6/port 11211 set /servers/cache/c7/host 192... set /servers/cache/c7/port 11211 ls /servers/cache
leader zookeeper cluster service provider 192.168.12.201 client 192.168.12.201
leader zookeeper cluster client service provider 192.168.12.201 service provider 192.168.12.123
192.168.12.123
Your app should only know... ...where your ZooKeeper is
Zookeeper CONFIGURATION PROVISIONING WITH... mariusz gil THANKS