当前位置:   article > 正文

ClickHouse/Doris vs Elasticsearch谁更胜一筹?_doris和es对比

doris和es对比

前言

我之前在ClickHouse vs Doris 读写性能比较 一文中,初步做了一下ClickHouse和Doris的读写性能比较,但由于数据样本比较小,且未发挥出所有硬件资源的性能,因此进行了第二轮压测。

本轮压测与上一轮的区别在于:

  1. 新加入了Elasticsearch搜索引擎
  2. ClickHouse和Doris均采用多并发写入,发挥最大性能
  3. 本轮测试得到了飞轮科技多位技术专家的指导,对Doris进行了一定的参数调优

环境准备(硬件机器配置同上一篇文章)

clickhouse集群

节点IP分片编号副本编号
ck93192.168.101.9311
ck94192.168.101.9412
ck96192.168.101.9621
ck97192.168.101.9722

doris集群

角色节点IP
FEck94192.168.101.94
BEck93192.168.101.93
BEck94192.168.101.94
BEck96192.168.101.96
BEck97192.168.101.97
BEck98192.168.101.98

FE 配置:

  1. meta_dir = /data01/doris/fe
  2. http_port = 58030
  3. rpc_port = 59020
  4. query_port = 59030
  5. edit_log_port = 59010
  6. priority_networks = 192.168.101.0/24
  7. enable_single_replica_load = true
  8. max_routine_load_task_concurrent_num = 50
  9. max_routine_load_task_num_per_be = 10

BE配置

  1. be_port = 59060
  2. webserver_port = 58040
  3. heartbeat_service_port = 59050
  4. brpc_port = 58060
  5. priority_networks = 192.168.101.0/24
  6. storage_root_path = /data01/doris/be
  7. enable_single_replica_load = true
  8. inverted_index_compaction_enable = true
  9. scan_thread_nice_value = 5

ES集群

计10个节点。

节点节点服务
node1ck93192.168.101.93:59200
node2ck93192.168.101.93:59201
node3ck94192.168.101.94:59200
node4ck94192.168.101.94:59201
node5ck96192.168.101.96:59200
node6ck96192.168.101.96:59201
node7ck97192.168.101.97:59200
node8ck97192.168.101.97:59201
node9ck98192.168.101.98:59200
node10ck98192.168.101.98:59201

数据准备

数据源

4个节点clickhouse-server日志,每个节点约2.5亿数据量,共计10亿数据,原始数据kafka压缩后为155GB。

建表语句

clickhouse

  1. --- 本地表
  2. create table log_test on cluster abc (
  3. `@@id` String NOT NULL CODEC(ZSTD(1)),
  4. `@message` String NOT NULL CODEC(ZSTD(1)) ,
  5. `@filehashkey` String NOT NULL CODEC(ZSTD(1)) ,
  6. `@collectiontime` DateTime64(3) CODEC(DoubleDelta, LZ4),
  7. `@hostname` LowCardinality(String) NOT NULL CODEC(ZSTD(1)) ,
  8. `@path` String NOT NULL CODEC(ZSTD(1)) ,
  9. `@rownumber` Int64 NOT NULL ,
  10. `@seq` Int64 NOT NULL ,
  11. `@ip` LowCardinality(String) NOT NULL CODEC(ZSTD(1)) ,
  12. `@topic` LowCardinality(String) NOT NULL CODEC(ZSTD(1)) ,
  13. `@timestamp` DateTime64(3) CODEC(DoubleDelta, LZ4),
  14. INDEX message_idx `@message` TYPE ngrambf_v1(5, 65535, 1, 0) GRANULARITY 1,
  15. PROJECTION p_cnt (
  16. SELECT `@ip`, `@path`, count() GROUP BY `@ip`, `@path`
  17. )
  18. )ENGINE = ReplicatedMergeTree
  19. PARTITION BY toYYYYMMDD(`@timestamp`)
  20. ORDER BY (`@timestamp`, `@ip`, `@path`);
  21. --- 分布式表
  22. create table dist_log_test on cluster abc as log_test engine = Distributed('abc', 'default', 'log_test')

Doris

  1. CREATE TABLE demo.log_test (
  2. `@@id` CHAR(34) NOT NULL ,
  3. `@message` STRING NOT NULL ,
  4. `@filehashkey` CHAR(34) NOT NULL,
  5. `@collectiontime` DATETIME(3) ,
  6. `@hostname` VARCHAR(20) NOT NULL ,
  7. `@path` VARCHAR(256) NOT NULL ,
  8. `@rownumber` BIGINT NOT NULL ,
  9. `@seq` BIGINT NOT NULL,
  10. `@ip` CHAR(16) NOT NULL ,
  11. `@topic` CHAR(16) NOT NULL,
  12. `@timestamp` DATETIME(3),
  13. INDEX idx_message_inv(`@message`) USING INVERTED PROPERTIES(
  14. "parser" = "unicode",
  15. "parser_mode" = "fine_grained",
  16. "support_phrase" = "true"
  17. )
  18. )
  19. DUPLICATE KEY(`@@id`)
  20. PARTITION BY RANGE(`@timestamp`) ()
  21. DISTRIBUTED BY HASH(`@@id`) BUCKETS AUTO
  22. ROLLUP (
  23. r1 (`@ip`, `@path`)
  24. )
  25. PROPERTIES (
  26. "replication_allocation" = "tag.location.default: 2",
  27. "dynamic_partition.enable" = "true",
  28. "dynamic_partition.time_unit" = "MONTH",
  29. "dynamic_partition.start" = "-12",
  30. "dynamic_partition.create_history_partition" = "true",
  31. "dynamic_partition.history_partition_num" = "12",
  32. "dynamic_partition.end" = "3",
  33. "dynamic_partition.prefix" = "p",
  34. "compression"="zstd",
  35. "compaction_policy"="time_series",
  36. "enable_single_replica_compaction"="true"
  37. );

写入配置

clickhouse_sinker

开启5个sinker并发,向clickhouse写入数据。配置如下:

  1. {
  2. "clickhouse": {
  3. "cluster": "abc",
  4. "db": "default",
  5. "hosts": [
  6. ["192.168.101.93", "192.168.101.94"],
  7. ["192.168.101.96", "192.168.101.97"]
  8. ],
  9. "port": 19000,
  10. "username": "default",
  11. "password": "123456",
  12. "maxOpenConns": 5,
  13. "retryTimes": 0
  14. },
  15. "kafka": {
  16. "brokers": "192.168.101.94:29092,192.168.101.96:29092,192.168.101.98:29092"
  17. },
  18. "tasks": [{
  19. "name": "log_test",
  20. "topic": "log_test",
  21. "earliest": true,
  22. "consumerGroup": "test_2024001",
  23. "parser": "fastjson",
  24. "tableName": "log_test",
  25. "autoSchema": true,
  26. "dynamicSchema":{
  27. "enable": false
  28. },
  29. "prometheusSchema": false,
  30. "bufferSize": 1000000,
  31. "flushInterval": 10
  32. }],
  33. "logLevel": "info"
  34. }

routine_load

  1. CREATE ROUTINE LOAD demo.log_test_10 ON log_test
  2. COLUMNS(`@message`,`@@id`,`@filehashkey`,`@collectiontime`,`@hostname`,`@path`,`@rownumber`,`@seq`,`@ip`,`@topic`,`@timestamp`)
  3. PROPERTIES
  4. (
  5. "desired_concurrent_number"="10",
  6. "max_error_number" = "500",
  7. "max_batch_interval" = "20",
  8. "max_batch_rows" = "1000000",
  9. "max_batch_size" = "536870912",
  10. "strict_mode" = "false",
  11. "format" = "json"
  12. )
  13. FROM KAFKA
  14. (
  15. "kafka_broker_list" = "192.168.101.94:29092,192.168.101.96:29092,192.168.101.98:29092",
  16. "kafka_topic" = "log_test",
  17. "kafka_partitions" = "0,1,2,3,4,5",
  18. "kafka_offsets" = "0,0,0,0,0,0"
  19. );

ElasticSearch settings and mapping

  1. {
  2. "order": 200,
  3. "index_patterns": [
  4. "estest_chenyc_log_*"
  5. ],
  6. "settings": {
  7. "index": {
  8. "codec": "best_compression",
  9. "refresh_interval": "10s",
  10. "number_of_shards": "10",
  11. "translog": {
  12. "sync_interval": "60s",
  13. "durability": "async"
  14. },
  15. "merge": {
  16. "scheduler": {
  17. "max_thread_count": "10"
  18. },
  19. "policy": {
  20. "max_merged_segment": "5g"
  21. }
  22. },
  23. "unassigned": {
  24. "node_left": {
  25. "delayed_timeout": "15m"
  26. }
  27. },
  28. "number_of_replicas": "1"
  29. }
  30. },
  31. "mappings": {
  32. "dynamic": true,
  33. "dynamic_templates": [
  34. {
  35. "message_field": {
  36. "path_match": "@message",
  37. "mapping": {
  38. "norms": false,
  39. "type": "text"
  40. },
  41. "match_mapping_type": "string"
  42. }
  43. },
  44. {
  45. "string_fields": {
  46. "mapping": {
  47. "type": "keyword"
  48. },
  49. "match_mapping_type": "string",
  50. "match": "*"
  51. }
  52. }
  53. ],
  54. "properties": {
  55. "@message": {
  56. "norms": false,
  57. "type": "text"
  58. },
  59. "@seq": {
  60. "type": "long"
  61. },
  62. "@timestamp": {
  63. "type": "date"
  64. },
  65. "@topic": {
  66. "type": "keyword"
  67. },
  68. "@filehashkey": {
  69. "type": "keyword"
  70. },
  71. "@@id": {
  72. "type": "keyword"
  73. },
  74. "@rownumber": {
  75. "type": "long"
  76. },
  77. "@ip": {
  78. "type": "keyword"
  79. },
  80. "@collectiontime": {
  81. "type": "date"
  82. },
  83. "@hostname": {
  84. "type": "keyword"
  85. },
  86. "@path": {
  87. "type": "keyword"
  88. }
  89. }
  90. },
  91. "aliases": {}
  92. }

资源配置:

(为了最大发挥es的写入性能,重新生成了一份数据,设置kafka的topic partition数为 30)

中台配置:

写入性能

clickhouse

并发数资源占用(sinker)资源占用(clickhouse)数据总量写入速度数据大小压缩后大小(含副本)
515vcpu|25G5vcpu|6G10亿1205k/s155GB95GB
5(有大查询)10vcpu|16G37vcpu|8G10亿890k/s155GB95GB

Doris

并发数资源占用(be)数据总量写入速度数据大小压缩后大小(含副本)
52~8vcpu|9GB10亿532k/s155GB161GB
102~11vcpu|10GB10亿559k/s155GB161GB
155-15vcpu|10GB10亿675k/s155GB161GB
203~12vcpu|9GB10亿609k/s155GB161GB
15并发,有大查询16~29vcpu|12GB10亿490k/s155GB161GB

cpu负载各个节点有所区别,部分节点cpu负载比较高(应该是被写入数据的节点),剩余节点CPU负载都维持在一个相对低的水平,和ClickHouse相当。

ElasticSearch

使用擎创科技内部的日志精析产品启动flink存储任务写入数据。

并发数ES节点资源占用数据总量写入速度数据大小压缩后大小(含副本)
307vcpu|38GB10亿106k/s155GB281GB
30(有大查询)11vcpu|39GB10亿75k/s155GB281GB

写入结论

ES:CK:Doris写入速度比为 1:6: 12。Doris写入性能是ES的6倍,ck是ES的12倍。

在本次测试中,数据均保留两副本,存储相同的数据,得出压缩比为ES:CK:Doris 为 1: 0.35: 0.57。即存储相同的数据量,Doris只需要ES近一半的存储资源,ClickHouse仅需ES三分之一的存储资源即可满足要求。

查询性能

依然使用上次的查询场景:

场景说明
场景1根据ip和path维度统计每个ip下path的个数
场景2统计每个ip下的Error日志的数量
场景3统计日志中出现Debug 和 query_id 为 cdb56920-2d39-4e6d-be99-dd6ef24cc66a 的条数
场景4统计出现Trace和gauge.apm_service_span出现的次数
场景5查询Error中出现READ_ONLY的日志明细
场景6查询日志中出现“上海”关键字的明细

查询语句:

场景数据库SQL语句
场景1clickhouseSELECT @ip, @path, count() FROM dist_log_test GROUP BY @ip,@path
场景1DorisSELECT @ip, @path, count() FROM log_test GROUP BY @ip,@path
场景1ElasticSearch|stats count by @ip,@path
场景2clickhouseSELECT @ip, count() FROM dist_log_test WHERE @message LIKE '%Error%' GROUP BY @ip
场景2DorisSELECT @ip, count() FROM log_test WHERE @message MATCH_ANY 'Error' GROUP BY @ip
场景2ElasticSearchError | stats count by @ip
场景3clickhouseSELECT count() FROM dist_log_test WHERE @message LIKE '%Debug%' AND @message LIKE '%cdb56920-2d39-4e6d-be99-dd6ef24cc66a%'
场景3DorisSELECT count() FROM log_test WHERE @message MATCH_ALL 'Debug cdb56920-2d39-4e6d-be99-dd6ef24cc66a'
场景3ElasticSearchDebug AND cdb56920-2d39-4e6d-be99-dd6ef24cc66a | stats by count
场景4clickhouseSELECT count() FROM dist_log_test WHERE @message LIKE '%Trace%' AND @message LIKE '%gauge.apm_service_span%'
场景4DorisSELECT count() FROM log_test WHERE @message MATCH_ALL 'Trace gauge.apm_service_span'
场景4ElasticSearchTrace AND gauge.apm_service_span |stats by count
场景5clickhouseSELECT * FROM dist_log_test WHERE @message LIKE '%Error%' AND @message LIKE '%READ_ONLY%'
场景5DorisSELECT * FROM log_test WHERE @message MATCH_ALL 'Error READ_ONLY'
场景5ElasticSearchError AND READ_ONLY
场景6clickhouseSELECT * FROM dist_log_test WHERE @message LIKE '%上海%'
场景6DorisSELECT * FROM log_test WHERE @message MATCH_ANY '上海'
场景6ElasticSearch上海

查询结果如下所示:

数据库场景1场景2场景3场景4场景5场景6
clickhouse无干扰查询
有写入时查询
0.064
0.181
16.284
22.156
1.688
3.994
12.879
35.167
16.065
33.792
14.694
31.244
Doris无干扰查询
有写入时查询
7.08
9.78
2.56
3.28
0.09
0.37
0.48
0.75
0.33
0.37
0.48
0.56
elasticsearch无干扰查询
有写入时查询
9.09
9.25
1.54
6.22
0.556
1.68
0.296
3.36
0.248
0.828
0.49
1.09

结论

在给出的6个场景中,除了场景1,ClickHouse凭借projection带来的预聚合加速明显更快之外,其余场景ClickHouse均慢于doris和ES,在全⽂检索的查询场景,落后近10倍以上。

得益于全⽂检索的加持,Doris与ES在模糊查询的场景下不分轩轾,各有千秋,但均比clickhouse快很多。

在数据库有⾼速写⼊时,三者都出现了⼀定的查询性能下降。但从实际效果来看,doris和ES因为本身就比较快,因此影响不是很大。ClickHouse的影响⽐较明显,在原本就⽐较慢的基础上,⼜有了近乎3倍的查询时间消耗。

整体结论

  • 写入性能: clickhouse > doris >> es
  • 数据压缩: clickhouse > doris > es
  • 查询性能:
    • 全文检索:Doris ≈ es > clickhouse
    • 聚合查询: clickhouse > doris ≈ es

在并发足够的情况下,clickhouse能轻松满足每秒100w+数据的写入。Doris写入性能相比之下要减半,并且不会随着并发数的增加而增加(并发数过多,反而写入更慢了)。但总体可以达到60w+每秒左右。三者之中,ES写入速度最慢,峰值仅能达到10w每秒左右。

在有大查询时,三者均对写入有一定影响,会造成写入性能下降25%左右。

压缩比方面,clickhouse和Doris均有比较优秀的压缩表现,而ES不仅没有压缩,反而数据有所膨胀。Doris相比与ES,有着近2倍的压缩比,而clickhouse更是达到了3倍之多。

查询方面,在聚合查询场景,clickhouse明显要更优秀,Doris和ES相对弱一些。

模糊查询场景,Doris与ES性能相当,都明显优于clickhouse。



本专栏知识点是通过<零声教育>的系统学习,进行梳理总结写下文章,对C/C++课程感兴趣的读者,可以点击链接,查看详细的服务:C/C++Linux服务器开发/高级架构师

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/326763
推荐阅读
相关标签
  

闽ICP备14008679号