Zookeeper vs Etcd

Zookeeper and Etcd are very good coordination of distributed systems, zookeeper originated in the Hadoop ecosystem, etcd popular because it is kubernetes background support.

This article will explain the advantages and disadvantages zookeeper and etcd in order to select a more appropriate system for distributed coordination based on your actual needs.

1. Zookeeper

Outline

zookeeper originated in Hadoop, and later evolved into a top-level Apache project. It has now been widely used in the Apache projects, such as Hadoop, kafka, solr and so on.

Zookeeper Architecture

zookeeper use ZAB protocol as its coherence protocol.
zookeeper work through as a team, working with a group node, to provide distributed capabilities, this group of node of the required number is odd.

The first node to communicate with other nodes, elect a leader, get the majority of votes to become leader, which is why you need an odd number of node, the other nodes are called follower.

When a client can connect to any connector ZooKeeper, client read request may be processed any of a node, the write request can be processed leader. So, add a new node can improve the speed of reading, but will not increase the writing speed.

For the CAP model, zookeeper security is CP.

ZNode

ZNode Structure

When storing data, using ZooKeeper tree structure, where each node is referred znode, when accessing a znode, desirable to provide an absolute path from the root.

Each ZNode can store data of up to 1MB, the user can:

  • Creating ZNode
  • Delete ZNode
  • Storing data to the specified ZNode
  • Reading data from the ZNode

zookeeper also provides a very important feature: watcher API.

zookeeper watches

用户可以对一个 ZNode 设置 watch,当这个 ZNode 发生了变化时,例如 创建、删除、数据变更、添加或移除子节点,watch API 就会发出通知,这是 zookeeper 非常重要的功能。

zookeeper 的 watch 有一个缺点,就是这个 watch 只能被触发一次,一旦发出了通知,如果还想对这个节点继续 watch,用户需要重新设置 watch。

优点

  • 非阻塞全部快照(达成最终一致)
  • 高效的内存管理
  • 高可靠
  • API 简单
  • 连接管理可以自动重试
  • ZooKeeper recipes 的实现是经过完整良好的测试的。
  • 有一套框架使得写新的 ZooKeeper recipes 非常简单。
  • 支持监听事件
  • 发生网络分区时,各个区都会开始选举 leader,那么节点数少的那个分区将会停止运行。

缺点

  • zookeeper 是 java 写的,那么自然就会继承 java 的缺点,例如 GC 暂停。
  • 如果开启了快照,数据会写入磁盘,此时 zookeeper 的读写操作会有一个暂时的停顿。
  • 对于每个 watch 请求,zookeeper 都会打开一个新的 socket 连接,这样 zookeeper 就需要实时管理很多 socket 连接,比较复杂。

etcd

概述

etcd 是用 go 开发的,出现的时间并不长,不像 zookeeper 那么悠久和有名,但是前景非常好。

etcd 是因为 kubernetes 而被人熟知的,kubernetes 的 kube master 使用 etcd 作为分布式存储获取分布式锁,这为 etcd 的强大做了背书。

etcd 使用 RAFT 算法实现的一致性,比 zookeeper 的 ZAB 算法更简单。

etcd 没有使用 zookeeper 的树形结构,而是提供了一个分布式的 key-value 存储。

特性:

  • 原子性
  • 一致性
  • 顺序一致性
  • 可串行化级别
  • 高可用
  • 可线性化

API

etcd3 提供了如下操作接口:

  • put - 添加一个新的 key-value 到存储中
  • get - 获取一个 key 的 value
  • range - obtaining a range of the key value, for example: key1 - key10
  • transaction - to read, compare, modify, write combination
  • watch - monitor one or a range of key, the changes will be notified

advantage

  • Supports incremental snapshots, snapshot to avoid the suspension of the issue of zookeeper
  • External heap memory, no garbage collection pauses problem
  • Did not need to be like zookeeper for each watch will be a socket connection, you can reuse
  • Each watch zookeeper only receive an event notification, etcd can be continuously monitored, without setting a watch again after triggering a watch
  • zookeeper will drop events, etcd3 hold an event window, all events will not be lost after the disconnected client

Shortcoming

  • If the timeout, or client and etcd network outage, client does not know exactly the status of the current operation
  • When leader election, etcd will abort the operation, and will not give up the response sent to the client
  • When a network partition, when the leader is in the small partition, the read request will be processed

to sum up

zookeeper is in java, adopted many Apache projects.

etcd go is developed mainly by Kubernetes used.

zookeeper is very stable, is a well-known distributed coordination system, etcd is a rising star, a bright future.

Because etcd is go to write, and now there is no good java client library, call via http way.

The zookeeper mature a lot in this regard, for other than the java programming language has a very good client library.

The specific choice of zookeeper or etcd, need to combine their respective characteristics to judge, as well as the development language you use according to your needs.

Since finishing translation:

https://medium.com/@Imesha94/apache-curator-vs-etcd3-9c1362600b26

Guess you like

Origin www.cnblogs.com/yogoup/p/12020477.html