Taming Pythons with ZooKeeper (Pyconfi edition)

1,010 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,010
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
14
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Taming Pythons with ZooKeeper (Pyconfi edition)

  1. 1. Taming Pythons with ZooKeeper PyCon Finland 2012
  2. 2. @nailor
  3. 3. Content Squad
  4. 4. Day to day operations• Consume boatloads of XML• Build database out ofit• Transcode audio• Enrich data• Build indexes• Ship indexes
  5. 5. Shipping
  6. 6. Pre-defined order
  7. 7. The naïve solution• Central orchestrator• Assume all machines are running• Run remote commands• We need to know all the quirks• Fail fast
  8. 8. Guess what? It breaks
  9. 9. ...and replacing isnt simple
  10. 10. New tool is needed• No central orchestrator• Assume some machines are always down• Run locally• Shift responsibility to system owners• Fail gracefully
  11. 11. CAP Theorem
  12. 12. The CAP Theorem1.Consistency2.Availability3.Partition tolerance
  13. 13. Pick two. Any two will do.
  14. 14. We went for CA
  15. 15. Why?• Users are mostly contained in single DC• Inside a single DC connections are quite robust• Remember the order? We need consistency• Availability is everything
  16. 16. How?
  17. 17. Apache ZooKeeper
  18. 18. What?• A distributed tree-like data structure• Simple primitives• Automatic leader elections• Guaranteed hard consistency• Ephemeral nodes
  19. 19. Tree-like structure / /dir/ /dir2/ /subdir/
  20. 20. Simple primitives● Guaranteed atomic operations● Counters● Change notifications
  21. 21. Automatic leader election● Nodes know who is the most up to date● If no leader can be picked, ZooKeeper refuses to work
  22. 22. Guaranteed hard consistency● Every change is sent to every node!● Quorum for all operations is always required
  23. 23. Ephemeral nodes● Node is present only if the client is alive
  24. 24. Library: zkPython
  25. 25. The Good:● Thin● Comes with ZooKeeper● Maintained by the Apache ZooKeeper project
  26. 26. The bad:● Thin● C bindings only, no PyPy for you
  27. 27. The ugly:● No documentation :(
  28. 28. There are others: Kazoo
  29. 29. The Good:● Pure Python● Recipes implemented● Used by many (Quora, Mozilla, reddit, Zope)
  30. 30. The bad:● Not much recipes done● Not owned by the mainline
  31. 31. The ugly:● Own implementation of the protocol
  32. 32. Dos and Donts
  33. 33. Dont ship large chunks
  34. 34. Monitor the ZooKeeper
  35. 35. Dont write there all the time
  36. 36. Stay in one DC
  37. 37. Spotify & ZooKeeper
  38. 38. Summary time!
  39. 39. Concurrency == hard
  40. 40. Distributed consistency == hard
  41. 41. No partitions? Go ZooKeeper!
  42. 42. Pick your weapon library
  43. 43. Remember tradeoffs
  44. 44. Thank you

×