ClickHouse is a high-performance open source analytical database developed by Yandex. Initially, ClickHouse was created for Yandex.Metrica tasks , but gradually found many uses both within Yandex and in other companies. I will tell you how ClickHouse is arranged internally, with an emphasis on the consequences of the chosen architecture from the point of view of an application developer.
The following topics will be covered:
- How ClickHouse stores data on disk and performs a query, why this storage method allows you to speed up analytical queries by several orders of magnitude, but is poorly suited for OLTP and key-value loads.
- How replication and sharding work, how to achieve linear scaling, and what to do with eventual consistency.
- How to diagnose problems on a ClickHouse production cluster.
Video:
The idea of ββthe report is quite simple: that if you use some tool or are going to use it, then it is advisable to at least in general terms imagine what is going on inside in order to avoid some wrong decisions and make the right decision. I will try to convey this understanding about ClickHouse today.
I have been working on ClickHouse recently. Before that, I worked at Yandex.Maps for several years. He was an applied developer. I worked a lot there with databases, with Postgres, so I am not yet very infected with the ClickHouse virus, I still remember what it means to be an applied developer. But, in principle, I already understand everything quite well.
. ClickHouse β , , . .
. . - . . β , ClickHouse .
- - .
- .
- , .
- DNS-.
? - , . . - , , - .
, , . . . , , .
ClickHouse :
- . ? , , . ? -, . , , . , , ClickHouse, , , . . . . .
- SQL. , . , SQL , . . . SQL . . . SQL , - , . , SQL , .
- . . . , , . , , , . . , . . , .
- , , ClickHouse. , . , ClickHouse, . . - json blob, , . , .
. , ., -. , . CounterID. hits, . Referer, -. . . , 100 .
. Referer, count, count. 10 .
. ?
-, :
- , , . . . . . : ConterID, Date, Referrer. , 100. , , .
- , , , . , , . , , . , .
- . .
, , . ClickHouse :
- , . ? β , - . ? ClickHouse β . , β . overhead , . SIMD . , , , , - .
- . .
, , , . -, , . . , . . - . , , , β CounterID, Date.
, ? CounterID, Date , , . , . .
ClickHouse . -, . . , . , , , . .
, , , , . . , . , 8 192 . . , , .
, , ? , . 1234 31 . 23 . , , , . , 1235. , , . , β . - , . , 8 000 .
, , . , ClickHouse . , Β« Β», , .
? . , . . . .
? Key-Value . - , , - , . , , .
, , 100 , , , , , . , , , - .
, , , . , , ClickHouse, . . . insert , .
, , . . - . , . . . . - .
? ClickHouse . MergeTree. , LSM . . . . , . .
, . β , . ., , , . β . . . .
ClickHouse? . . ? insert , . . - .
, , - ClickHouse, , . , , 1 000 , , .
. - . . . merge.
ClickHouse . , . , M N. , , N+1.
. N+1. .
? . , , - , , , , .
ClickHouse? ( β ) 200 , . ClickHouse . 300 , , . , ClickHouse, . ClickHouse Graphite. . . , . , - . .
. ClickHouse, . .
- , . .
- , , .
- ClickHouse , , . .
ClickHouse? .
? β . - . , . local_table.
distributed ? view , . . . , . , , β . .
? select from distributed_table. distributed_table local_table. .
. , . . . - , . distributed . Distributed .
benchmark. . - . . .
. . . . , . 140 , 140 , . . . , 140- , , . .
?
, , , distributed , , , , . , , - . , .
, , distributed , .
-, , . . distributed , - .
. . , . . .
? . . , joins , , joins , , .
ClickHouse. , , . , . - , . , , . . . , .
ClickHouse - , β ReplicatedMergeTree. , .
. . , . . . . . .
:
- INSERT β
- FETCH β
- MERGE β
? . , 1 β , . ZooKeeper. . . , , ZooKeeper.
- . , - , , fetch.
merge, . . . Merge , . . , , , . . . 2 β . , , ZooKeeper, merge.
checksums. - , , . . -. , . . , , , .
CAP-, . . - , , , : , - .
ClickHouse . , , , , , , . β : , . . , . , , .
. ClickHouse? -. ZK 3- -, , , 2-. , , .
: Β« - ?Β». - ZooKeeper. , - - . , . , .
? ? , , quorum ZK, . . , , . .
: distributed_table, replicated_table . . . ClickHouse . . . N . distributed , β , . , . . - , .
consistency. - . distributed , , . .
ClickHouse?
- column-oriented , .
- β SQL .
- OLTP, . Key-Value, . , . Key-Value blob, .
- , distributed .
- , replicate .
- open source community.
! . ! . , ClickHouse . - - , ?
? , , , retry. retry, , , ClickHouse , retry. , , . ClickHouse . ?
. ZK checksums . , 100 β . - , β , . , ClickHouse .
. . 10 000 , , ?
. .
. . , , 10 000. , , , .
, .
. . , ?
, checksum. checksum , .
. . distributed replicated . , . - , - , , - ?
, . . , . -, max_parallel_replicas. ? , . , , . ClickHouse β . , . , max_parallel_replicas, , . .
?
, . , .
, !
! . , , . . 8 000 -. . - ? - ?
, . , , , , , ClickHouse .
? -, , - . , . . . . , ClickHouse, Kafka. Kafka lock, Kafka ClickHouse. .
, . . . . distributed , . , , distributed . , ?
Distributed . , , . , local_tables, , , , .
. , . - , , , , ? .
, . , , . .
. . , ?
, distributed . 500 , , . 500 . . , . 100 , . . .
!
? - , , , ?
, , , . β . . Β«alter table drop partitionΒ» , .
, - , . . , , . . . , . ClickHouse , CollapsingMergeTree. , . - , : β , β . - . - .
-. , , ClickHouse : Β« ?Β», .
. , , , Kafka ? . . -, .
- replicated . ? distributed .
replicated ? , , , . - ? Slave , slave?
Kafka ?
Kafka . Kafka .
Kafka ZK.
. , , Kafka . , ClickHouse .
ClickHouse , ZK .
, , quorum ZK, . quorum .
replicated , ? , . distributed , - . , . β . replicated .
. ? instants ?
, ClickHouse , max_memory_usage. , . ? . . . ClickHouse - . , ? o_direct - . ClickHouse . - ( ) . , , . , .
ClickHouse ? , . . - , , count, .
? group by . , referrers - referrers, urls. . , , , group by , .
?
.
- , ? , 32 GB ? . ., .
, . 128 GB.
instance 128 , ?
, , . , , . , . , , .
, ! ?
. , . , , . , . , . .
?
, 70 .
!
! . , ClickHouse http- . - roadmap, ?
. http, http- , JDBC- . , - . . - , Go , , , . C++ , ClickHouse, . , , . . . . , . .
! , . , Impala HDFS , . , , HDFS?
. ClickHouse . merge , . , , HDFS . , HDFS , .
. . ?
, , . . - , -, .
β HDFS *opened*, .
. . HDFS ?
. . HDFS , , .
- .
HDFS . , , .
, .
!