zookeeperObservers.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta content="Apache Forrest" name="Generator">
  6. <meta name="Forrest-version" content="0.9">
  7. <meta name="Forrest-skin-name" content="pelt">
  8. <title>ZooKeeper Observers</title>
  9. <link type="text/css" href="skin/basic.css" rel="stylesheet">
  10. <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
  11. <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
  12. <link type="text/css" href="skin/profile.css" rel="stylesheet">
  13. <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
  14. <link rel="shortcut icon" href="images/favicon.ico">
  15. </head>
  16. <body onload="init()">
  17. <script type="text/javascript">ndeSetTextSize();</script>
  18. <div id="top">
  19. <!--+
  20. |breadtrail
  21. +-->
  22. <div class="breadtrail">
  23. <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://zookeeper.apache.org/">ZooKeeper</a> &gt; <a href="http://zookeeper.apache.org/">ZooKeeper</a><script src="skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
  24. </div>
  25. <!--+
  26. |header
  27. +-->
  28. <div class="header">
  29. <!--+
  30. |start group logo
  31. +-->
  32. <div class="grouplogo">
  33. <a href="http://hadoop.apache.org/"><img class="logoImage" alt="Hadoop" src="images/hadoop-logo.jpg" title="Apache Hadoop"></a>
  34. </div>
  35. <!--+
  36. |end group logo
  37. +-->
  38. <!--+
  39. |start Project Logo
  40. +-->
  41. <div class="projectlogo">
  42. <a href="http://zookeeper.apache.org/"><img class="logoImage" alt="ZooKeeper" src="images/zookeeper_small.gif" title="ZooKeeper: distributed coordination"></a>
  43. </div>
  44. <!--+
  45. |end Project Logo
  46. +-->
  47. <!--+
  48. |start Search
  49. +-->
  50. <div class="searchbox">
  51. <form action="http://www.google.com/search" method="get" class="roundtopsmall">
  52. <input value="zookeeper.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">&nbsp;
  53. <input name="Search" value="Search" type="submit">
  54. </form>
  55. </div>
  56. <!--+
  57. |end search
  58. +-->
  59. <!--+
  60. |start Tabs
  61. +-->
  62. <ul id="tabs">
  63. <li>
  64. <a class="unselected" href="http://zookeeper.apache.org/">Project</a>
  65. </li>
  66. <li>
  67. <a class="unselected" href="https://cwiki.apache.org/confluence/display/ZOOKEEPER/">Wiki</a>
  68. </li>
  69. <li class="current">
  70. <a class="selected" href="index.html">ZooKeeper 3.4 Documentation</a>
  71. </li>
  72. </ul>
  73. <!--+
  74. |end Tabs
  75. +-->
  76. </div>
  77. </div>
  78. <div id="main">
  79. <div id="publishedStrip">
  80. <!--+
  81. |start Subtabs
  82. +-->
  83. <div id="level2tabs"></div>
  84. <!--+
  85. |end Endtabs
  86. +-->
  87. <script type="text/javascript"><!--
  88. document.write("Last Published: " + document.lastModified);
  89. // --></script>
  90. </div>
  91. <!--+
  92. |breadtrail
  93. +-->
  94. <div class="breadtrail">
  95. &nbsp;
  96. </div>
  97. <!--+
  98. |start Menu, mainarea
  99. +-->
  100. <!--+
  101. |start Menu
  102. +-->
  103. <div id="menu">
  104. <div onclick="SwitchMenu('menu_1.1', 'skin/')" id="menu_1.1Title" class="menutitle">Overview</div>
  105. <div id="menu_1.1" class="menuitemgroup">
  106. <div class="menuitem">
  107. <a href="index.html">Welcome</a>
  108. </div>
  109. <div class="menuitem">
  110. <a href="zookeeperOver.html">Overview</a>
  111. </div>
  112. <div class="menuitem">
  113. <a href="zookeeperStarted.html">Getting Started</a>
  114. </div>
  115. <div class="menuitem">
  116. <a href="releasenotes.html">Release Notes</a>
  117. </div>
  118. </div>
  119. <div onclick="SwitchMenu('menu_1.2', 'skin/')" id="menu_1.2Title" class="menutitle">Developer</div>
  120. <div id="menu_1.2" class="menuitemgroup">
  121. <div class="menuitem">
  122. <a href="api/index.html">API Docs</a>
  123. </div>
  124. <div class="menuitem">
  125. <a href="zookeeperProgrammers.html">Programmer's Guide</a>
  126. </div>
  127. <div class="menuitem">
  128. <a href="javaExample.html">Java Example</a>
  129. </div>
  130. <div class="menuitem">
  131. <a href="zookeeperTutorial.html">Barrier and Queue Tutorial</a>
  132. </div>
  133. <div class="menuitem">
  134. <a href="recipes.html">Recipes</a>
  135. </div>
  136. </div>
  137. <div onclick="SwitchMenu('menu_selected_1.3', 'skin/')" id="menu_selected_1.3Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Admin &amp; Ops</div>
  138. <div id="menu_selected_1.3" class="selectedmenuitemgroup" style="display: block;">
  139. <div class="menuitem">
  140. <a href="zookeeperAdmin.html">Administrator's Guide</a>
  141. </div>
  142. <div class="menuitem">
  143. <a href="zookeeperQuotas.html">Quota Guide</a>
  144. </div>
  145. <div class="menuitem">
  146. <a href="zookeeperJMX.html">JMX</a>
  147. </div>
  148. <div class="menupage">
  149. <div class="menupagetitle">Observers Guide</div>
  150. </div>
  151. </div>
  152. <div onclick="SwitchMenu('menu_1.4', 'skin/')" id="menu_1.4Title" class="menutitle">Contributor</div>
  153. <div id="menu_1.4" class="menuitemgroup">
  154. <div class="menuitem">
  155. <a href="zookeeperInternals.html">ZooKeeper Internals</a>
  156. </div>
  157. </div>
  158. <div onclick="SwitchMenu('menu_1.5', 'skin/')" id="menu_1.5Title" class="menutitle">Miscellaneous</div>
  159. <div id="menu_1.5" class="menuitemgroup">
  160. <div class="menuitem">
  161. <a href="https://cwiki.apache.org/confluence/display/ZOOKEEPER">Wiki</a>
  162. </div>
  163. <div class="menuitem">
  164. <a href="https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ">FAQ</a>
  165. </div>
  166. <div class="menuitem">
  167. <a href="http://zookeeper.apache.org/mailing_lists.html">Mailing Lists</a>
  168. </div>
  169. </div>
  170. <div id="credit"></div>
  171. <div id="roundbottom">
  172. <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
  173. <!--+
  174. |alternative credits
  175. +-->
  176. <div id="credit2"></div>
  177. </div>
  178. <!--+
  179. |end Menu
  180. +-->
  181. <!--+
  182. |start content
  183. +-->
  184. <div id="content">
  185. <div title="Portable Document Format" class="pdflink">
  186. <a class="dida" href="zookeeperObservers.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
  187. PDF</a>
  188. </div>
  189. <h1>ZooKeeper Observers</h1>
  190. <div id="front-matter">
  191. <div id="minitoc-area">
  192. <ul class="minitoc">
  193. <li>
  194. <a href="#ch_Introduction">Observers: Scaling ZooKeeper Without Hurting Write Performance
  195. </a>
  196. </li>
  197. <li>
  198. <a href="#sc_UsingObservers">How to use Observers</a>
  199. </li>
  200. <li>
  201. <a href="#ch_UseCases">Example use cases</a>
  202. </li>
  203. </ul>
  204. </div>
  205. </div>
  206. <a name="ch_Introduction"></a>
  207. <h2 class="h3">Observers: Scaling ZooKeeper Without Hurting Write Performance
  208. </h2>
  209. <div class="section">
  210. <p>
  211. Although ZooKeeper performs very well by having clients connect directly
  212. to voting members of the ensemble, this architecture makes it hard to
  213. scale out to huge numbers of clients. The problem is that as we add more
  214. voting members, the write performance drops. This is due to the fact that
  215. a write operation requires the agreement of (in general) at least half the
  216. nodes in an ensemble and therefore the cost of a vote can increase
  217. significantly as more voters are added.
  218. </p>
  219. <p>
  220. We have introduced a new type of ZooKeeper node called
  221. an <em>Observer</em> which helps address this problem and
  222. further improves ZooKeeper's scalability. Observers are non-voting members
  223. of an ensemble which only hear the results of votes, not the agreement
  224. protocol that leads up to them. Other than this simple distinction,
  225. Observers function exactly the same as Followers - clients may connect to
  226. them and send read and write requests to them. Observers forward these
  227. requests to the Leader like Followers do, but they then simply wait to
  228. hear the result of the vote. Because of this, we can increase the number
  229. of Observers as much as we like without harming the performance of votes.
  230. </p>
  231. <p>
  232. Observers have other advantages. Because they do not vote, they are not a
  233. critical part of the ZooKeeper ensemble. Therefore they can fail, or be
  234. disconnected from the cluster, without harming the availability of the
  235. ZooKeeper service. The benefit to the user is that Observers may connect
  236. over less reliable network links than Followers. In fact, Observers may be
  237. used to talk to a ZooKeeper server from another data center. Clients of
  238. the Observer will see fast reads, as all reads are served locally, and
  239. writes result in minimal network traffic as the number of messages
  240. required in the absence of the vote protocol is smaller.
  241. </p>
  242. </div>
  243. <a name="sc_UsingObservers"></a>
  244. <h2 class="h3">How to use Observers</h2>
  245. <div class="section">
  246. <p>Setting up a ZooKeeper ensemble that uses Observers is very simple,
  247. and requires just two changes to your config files. Firstly, in the config
  248. file of every node that is to be an Observer, you must place this line:
  249. </p>
  250. <pre class="code">
  251. peerType=observer
  252. </pre>
  253. <p>
  254. This line tells ZooKeeper that the server is to be an Observer. Secondly,
  255. in every server config file, you must add :observer to the server
  256. definition line of each Observer. For example:
  257. </p>
  258. <pre class="code">
  259. server.1:localhost:2181:3181:observer
  260. </pre>
  261. <p>
  262. This tells every other server that server.1 is an Observer, and that they
  263. should not expect it to vote. This is all the configuration you need to do
  264. to add an Observer to your ZooKeeper cluster. Now you can connect to it as
  265. though it were an ordinary Follower. Try it out, by running:</p>
  266. <pre class="code">
  267. bin/zkCli.sh -server localhost:2181
  268. </pre>
  269. <p>
  270. where localhost:2181 is the hostname and port number of the Observer as
  271. specified in every config file. You should see a command line prompt
  272. through which you can issue commands like <em>ls</em> to query
  273. the ZooKeeper service.
  274. </p>
  275. </div>
  276. <a name="ch_UseCases"></a>
  277. <h2 class="h3">Example use cases</h2>
  278. <div class="section">
  279. <p>
  280. Two example use cases for Observers are listed below. In fact, wherever
  281. you wish to scale the numbe of clients of your ZooKeeper ensemble, or
  282. where you wish to insulate the critical part of an ensemble from the load
  283. of dealing with client requests, Observers are a good architectural
  284. choice.
  285. </p>
  286. <ul>
  287. <li>
  288. <p> As a datacenter bridge: Forming a ZK ensemble between two
  289. datacenters is a problematic endeavour as the high variance in latency
  290. between the datacenters could lead to false positive failure detection
  291. and partitioning. However if the ensemble runs entirely in one
  292. datacenter, and the second datacenter runs only Observers, partitions
  293. aren't problematic as the ensemble remains connected. Clients of the
  294. Observers may still see and issue proposals.</p>
  295. </li>
  296. <li>
  297. <p>As a link to a message bus: Some companies have expressed an
  298. interest in using ZK as a component of a persistent reliable message
  299. bus. Observers would give a natural integration point for this work: a
  300. plug-in mechanism could be used to attach the stream of proposals an
  301. Observer sees to a publish-subscribe system, again without loading the
  302. core ensemble.
  303. </p>
  304. </li>
  305. </ul>
  306. </div>
  307. <p align="right">
  308. <font size="-2"></font>
  309. </p>
  310. </div>
  311. <!--+
  312. |end content
  313. +-->
  314. <div class="clearboth">&nbsp;</div>
  315. </div>
  316. <div id="footer">
  317. <!--+
  318. |start bottomstrip
  319. +-->
  320. <div class="lastmodified">
  321. <script type="text/javascript"><!--
  322. document.write("Last Published: " + document.lastModified);
  323. // --></script>
  324. </div>
  325. <div class="copyright">
  326. Copyright &copy;
  327. 2008-2013 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
  328. </div>
  329. <!--+
  330. |end bottomstrip
  331. +-->
  332. </div>
  333. </body>
  334. </html>