zookeeper学习
2015-12-02 22:13
393 查看
1. zookeeper设计目标:协调分布式环境下的数据更新获取一致性;适合存储小数据(以KB单位衡量,默认数据不能超过1M),不是用来当做数据库存储大对象,对于大数据可存储在NFS或者HDFS上,在zookeeper上指向实际地址;高性能,高可用,严格的顺序访问。
2. zookeeper的节点内容全部存储在内存,以实现高吞吐,低延时
3. 内存维护zk所有服务的视图,通过事务日志和快照持久化。
4. 读大于写的场景有很高的性能(10:1)
5. 更新数据时,先写磁盘,再刷新内存数据;写请求都会forward给leader;zxid(zk的事务ID):每次改变都会产生一个唯一的zxid,如果zxid1 < zxid2则有zxid1在zxid2之前发生的语义。实现中zxid是一个64位的数字,它高32位是epoch用来标识leader关系是否改变,每次一个leader被选出来,它都会有一个新的epoch,标识当前属于那个leader的统治时期。低32位用于递增计数。
6. zk自身的选举还是比较快的(默认是fast paxos算法),In our observations, ZooKeeper takes less than 200ms to elect a new leader.
7. The current implementation requires that the timeout be a minimum of 2 times the tickTime (as set in the server configuration) and a maximum of 20 times the tickTime. 客户端连接超时设置必须在4秒到40秒之间(ticktime=2000ms),session过期是由zk集群服务器管理,而不是客户端;客户端在创建连接时可以指定session过期时间,不指定时为20*ticktime。
8. Another parameter to the ZooKeeper session establishment call is the default watcher. Watchers are notified when any state change occurs in the client.建立连接时指定默认的watcher将获得状态改变的所有通知。
9. 一致性保证:顺序一致性;读和写是原子的;最终一致性视图;
10. 节点上设置的watche是一次性的。 ZooKeeper provides an ordering guarantee: a client will never see a change for which it has set a watch until it first sees the watch event.zk保证先看到watch事件然后才能看到数据改变,同一个客户端将有一致性的顺序,不同客户端时间上有差异(网络延迟等原因)。
A client will see a watch event for a znode it is watching before seeing the new data that corresponds to that znode.
11. 由于节点上设置的watche是一次性的,获取到watch event时,需要重新设置watch,然而这中间会出现短暂的真空时间带,可能会丢失watch事件。这时采用连接全局的watcher可能更好。另外watch对象实例只触发一次,比如一个watch 对象被注册到(可以是同一个节点或者多个节点)多个事件上getData()和exists(),该watch对象只会响应最后注册的节点事件,如果exists()是最后注册的事件,则在节点被删除,仅对应于exists()的watch对象会被调用
12. 客户端设置的watcher由它连接到的那台zk服务器维护,zk集群的其他服务不知道;连接丢失时,可能造成watch事件丢失。
Watches are maintained locally at the ZooKeeper server to which the client is connected. This allows watches to be lightweight to set, maintain, and dispatch. When a client connects to a new server, the watch will be triggered for any session events. Watches
will not be received while disconnected from a server. When a client reconnects, any previously registered watches will be reregistered and triggered if needed. In general this all occurs transparently. There is one case where a watch may be missed: a watch
for the existence of a znode not yet created will be missed if the znode is created and deleted while disconnected.
13. ACL<idspec, permissions>设置节点上各种访问类型权限的ids(id可以是IP表达式),作用仅限于当前节点不递归。五种权限:CREATE/READ/WRITE/DELETE/ADMIN
14. 保证读取到最新数据,先调用sync(),再调用getData
15. 数据目录和日志目录放在不同的磁盘,提高zk性能。堆空间设置要小于物理内存,避免使用swap交换分区。
16. 清除data目录下的快照文件(cron job) java -cp zookeeper.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:lib/log4j-1.2.15.jar:conf org.apache.zookeeper.server.PurgeTxnLog <dataDir> <snapDir> -n <count>
自动清理:
17. 使用daemontools or SMF自动重启zk服务
18. 对于一台zk服务的数据文件损坏,Delete all the files in datadir/version-2 and datalogdir/version-2/. Restart the server. 备份数据时,
全量备份leader的快照文件和事务日志文件
2. zookeeper的节点内容全部存储在内存,以实现高吞吐,低延时
3. 内存维护zk所有服务的视图,通过事务日志和快照持久化。
4. 读大于写的场景有很高的性能(10:1)
5. 更新数据时,先写磁盘,再刷新内存数据;写请求都会forward给leader;zxid(zk的事务ID):每次改变都会产生一个唯一的zxid,如果zxid1 < zxid2则有zxid1在zxid2之前发生的语义。实现中zxid是一个64位的数字,它高32位是epoch用来标识leader关系是否改变,每次一个leader被选出来,它都会有一个新的epoch,标识当前属于那个leader的统治时期。低32位用于递增计数。
6. zk自身的选举还是比较快的(默认是fast paxos算法),In our observations, ZooKeeper takes less than 200ms to elect a new leader.
7. The current implementation requires that the timeout be a minimum of 2 times the tickTime (as set in the server configuration) and a maximum of 20 times the tickTime. 客户端连接超时设置必须在4秒到40秒之间(ticktime=2000ms),session过期是由zk集群服务器管理,而不是客户端;客户端在创建连接时可以指定session过期时间,不指定时为20*ticktime。
8. Another parameter to the ZooKeeper session establishment call is the default watcher. Watchers are notified when any state change occurs in the client.建立连接时指定默认的watcher将获得状态改变的所有通知。
9. 一致性保证:顺序一致性;读和写是原子的;最终一致性视图;
10. 节点上设置的watche是一次性的。 ZooKeeper provides an ordering guarantee: a client will never see a change for which it has set a watch until it first sees the watch event.zk保证先看到watch事件然后才能看到数据改变,同一个客户端将有一致性的顺序,不同客户端时间上有差异(网络延迟等原因)。
A client will see a watch event for a znode it is watching before seeing the new data that corresponds to that znode.
11. 由于节点上设置的watche是一次性的,获取到watch event时,需要重新设置watch,然而这中间会出现短暂的真空时间带,可能会丢失watch事件。这时采用连接全局的watcher可能更好。另外watch对象实例只触发一次,比如一个watch 对象被注册到(可以是同一个节点或者多个节点)多个事件上getData()和exists(),该watch对象只会响应最后注册的节点事件,如果exists()是最后注册的事件,则在节点被删除,仅对应于exists()的watch对象会被调用
12. 客户端设置的watcher由它连接到的那台zk服务器维护,zk集群的其他服务不知道;连接丢失时,可能造成watch事件丢失。
Watches are maintained locally at the ZooKeeper server to which the client is connected. This allows watches to be lightweight to set, maintain, and dispatch. When a client connects to a new server, the watch will be triggered for any session events. Watches
will not be received while disconnected from a server. When a client reconnects, any previously registered watches will be reregistered and triggered if needed. In general this all occurs transparently. There is one case where a watch may be missed: a watch
for the existence of a znode not yet created will be missed if the znode is created and deleted while disconnected.
13. ACL<idspec, permissions>设置节点上各种访问类型权限的ids(id可以是IP表达式),作用仅限于当前节点不递归。五种权限:CREATE/READ/WRITE/DELETE/ADMIN
14. 保证读取到最新数据,先调用sync(),再调用getData
15. 数据目录和日志目录放在不同的磁盘,提高zk性能。堆空间设置要小于物理内存,避免使用swap交换分区。
16. 清除data目录下的快照文件(cron job) java -cp zookeeper.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:lib/log4j-1.2.15.jar:conf org.apache.zookeeper.server.PurgeTxnLog <dataDir> <snapDir> -n <count>
自动清理:
autopurge.snapRetainCount=5 # The number of snapshots to retain in dataDir autopurge.purgeInterval=3 # Purge task interval in hours Set to "0" to disable auto purge feature
17. 使用daemontools or SMF自动重启zk服务
18. 对于一台zk服务的数据文件损坏,Delete all the files in datadir/version-2 and datalogdir/version-2/. Restart the server. 备份数据时,
全量备份leader的快照文件和事务日志文件
相关文章推荐
- Shell脚本实现自动安装zookeeper
- 基于Zookeeper的使用详解
- mesos + marathon + docker部署
- 基于zk的配置管理
- SolrCloud4.9+zookeeper在CentOS上的搭建与安装
- 基于外部ZooKeeper的GlusterFS作为分布式文件系统的完全分布式HBase集群安装指南
- redis集群搭建
- 使用 RMI + ZooKeeper 实现远程调用框架
- 轻量级分布式 RPC 框架
- 整合Kafka到Spark Streaming——代码示例和挑战
- HBase 系统架构
- 使用zookeeper实现分布式共享锁
- 将Zookeeper集成到你的应用中
- 基于zookeeper+leveldb搭建activemq集群
- Fourinone四合一分布式计算框架整体介绍
- windows 64位 安装zookeeper
- 工作中的zookeeper
- storm
- zookeeper技术浅析
- ZOOKEEPER的作用