2012年4月13日星期五

zookeeper笔记

zookeeper是hadoop的开源子项目。地址:http://zookeeper.apache.org
1. zookeeper是分布式的;
2. zookeeper是开源的;
3. zookeeper是一个协调服务,用于协调分布式应用的;
4. 典型应用:同步,配置维护,集群和命名服务;
设计目标:
1. 简单易用
2. 互相复制
3. 有序操作
4. 性能强大,处理速度快;
命名空间被设计成很类似一个文件系统,只不过无论是文件还是文件夹,都会有它自己的value。
zookeeper保证:
  • 顺序一致性 - Updates from a client will be applied in the order that they were sent.
  • 原子性 - Updates either succeed or fail. No partial results.
  • 单一的系统视图 - A client will see the same view of the service regardless of the server that it connects to.
  • 可靠性 - Once an update has been applied, it will persist from that time forward until a client overwrites the update.
  • 及时性 - The clients view of the system is guaranteed to be up-to-date within a certain time bound.

zookeeper的简单API:

create  creates a node at a location in the tree


delete  deletes a node
exists  tests if a node exists at a location
get data  reads the data from a node
set data writes data to a node
get children retrieves a list of children of a node
sync  waits for data to be propagated


更多可以查看zookeeper的官方文档:http://zookeeper.apache.org/doc/r3.3.2/zookeeperOver.html
zookeeper的应用场景:
1. 实时配置信息(client有一个watcher监控变化,实时改变)
2. 全局变量(是分布式应用级的,而非某单独事例)
3. 动态数据获取和更新(动态数据获取,以及人为更新,可以不通过接口方式实现)
4. 命名服务(Naming)
5. push的心跳检测,可以通过配置检测服务与zookeeper交互,而不直接与server交互)
6. 分布式锁(有点类似memcached的mutex模式中的add)
7. 集群, 例如分布式服务管理,动态增加或删除一个分布式服务,而无需重启。
8. 分布式队列
一个使用zookeeper作为协调RMI服务的例子。
目的:
         使用zookeeper作为RMI协调服务。在使用spring管理RMI服务的基础上,修改spring加载RMI的代码,加入zookeeper,使得spring由固定代理一个指定的RMI stub,变为动态加载多个RMI stub并且可以动态增减。

没有评论:

发表评论