ClickHouse Keeper: Coordination without the drawbacks没有缺点的分布式协作系统

ClickHouse Keeper 介绍

现代分布式系统需要一个共享和可靠的信息存储库和共识系统来协调和同步分布式操作。对于ClickHouse来说,ZooKeeper最初是被选中的。它的广泛使用是可靠的,提供了简单而强大的API,并提供了合理的性能。

然而,不仅仅是性能,资源效率和可扩展性一直是ClickHouse的首要考虑因素。ZooKeeper作为一个Java生态系统项目,并不能很好地适应我们主要的c++代码库,当ClickHouse在越来越大的规模上使用它时,ClickHouse开始遇到资源使用和运营方面的挑战。为了克服ZooKeeper的这些缺点,ClickHouse团队从零开始构建ClickHouse Keeper,考虑到ClickHouse项目需要解决的额外需求和目标。

ClickHouse Keeper是什么?

没有缺点的分布式协作系统,在ClickHouse集群中,可以直接替换zookeeper
Open-source coordination that scales
ClickHouse Keeper solves the well-known drawbacks of ZooKeeper and makes many additional improvements.
详见官网介绍

从官网给出的性能测试看,Keeper在内存利用率方面完胜zookeeper
ClickHouse Keeper: Coordination without the drawbacks没有缺点的分布式协作系统_第1张图片

ClickHouse Keeper的优点

为了克服ZooKeeper的一些缺点,ClickHouse开始根据自己的需求从头开始构建ClickHouse原生Keeper,并针对ClickHouse的使用进行了优化。

  • Easier setup and operation
  • No overflow issues
  • Better compression
  • Faster recovery
  • Less memory used
  • Additional guarantees

是否可直接替换zookeeper

Keeper是用c++编写的ZooKeeper的替代品,具有完全兼容的客户端协议和相同的数据模型,并具有这些改进

  • Compatible client protocol (all clients work out of the box)
  • The same state machine (data model)
  • Better guarantees (optionally allows linearizable reads)
  • Uses Raft algorithm (NuRaft implementation)
  • Optional TLS for clients and internal communication

什么场景下适合替换?

ClickHouse Keeper: Coordination without the drawbacks没有缺点的分布式协作系统_第2张图片

与zookeeper协同算法的主要区别?

  • ZooKeeper是用Java实现的,它的协调算法:ZooKeeper Atomic Broadcast (ZAB),不提供读的线性性保证。
  • 与ZooKeeper不同,ClickHouse Keeper是用c++编写的,并使用RAFT算法实现。该算法允许读写的线性化,并且有几种不同语言的开源实现。
    详细比较参见:ClickHouse Keeper: A ZooKeeper alternative written in C++

如何安装部署

详见clickhouse-keeper

主要配置文件

  • clickhouse-keeper.xml

    <keeper_server>
        <tcp_port>2181tcp_port>
        <server_id>1server_id>
        <log_storage_path>/var/lib/clickhouse/coordination/loglog_storage_path>
        <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshotssnapshot_storage_path>
    
        <coordination_settings>
            <operation_timeout_ms>10000operation_timeout_ms>
            <session_timeout_ms>30000session_timeout_ms>
            <raft_logs_level>traceraft_logs_level>
        coordination_settings>
    
        <raft_configuration>
            <server>
                <id>1id>
                <hostname>zoo1hostname>
                <port>9234port>
            server>
            <server>
                <id>2id>
                <hostname>zoo2hostname>
                <port>9234port>
            server>
            <server>
                <id>3id>
                <hostname>zoo3hostname>
                <port>9234port>
            server>
        raft_configuration>
    keeper_server>
    
  • 在clickhouse集群的配置文件metrika.xml文件中增加如下配置:

        <zookeeper-servers>
            <node>
                <host>chnode1.domain.comhost>
                <port>9181port>
            node>
            <node>
                <host>chnode2.domain.comhost>
                <port>9181port>
            node>
            <node>
                <host>chnode3.domain.comhost>
                <port>9181port>
            node>
        zookeeper-servers>
    

Four Letter Word Commands

ClickHouse Keeper还提供4字命令,这与Zookeeper几乎相同。每个命令由四个字母组成,如mntr、stat等。还有一些更有趣的命令:stat提供一些关于服务器和连接的客户端的一般信息,而srvr和cons分别提供关于服务器和连接的详细信息。

4lw命令有一个白名单配置,默认值为conf、cons、crst、envi、ruok、srst、srvr、stat、wchs、dirs、mntr、isro、rcvr、apiv、csnp、lif、rqld、ydld。

echo mntr | nc localhost 2181

你可能感兴趣的:(clickhouse,分布式)