Skip to content

Commit b3a54ba

Browse files
committed
ck async insert
1 parent 84c3fe4 commit b3a54ba

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Database/OLAP/Clickhouse.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ categories:
2929
- 7. [Explain](#explain)
3030
- 8. [Tips](#tips)
3131

32-
💠 2025-07-01 16:50:20
32+
💠 2025-07-01 20:46:45
3333
****************************************
3434
# Clickhouse
3535
> [Official Site](https://clickhouse.com)
@@ -208,6 +208,9 @@ categories:
208208
![](./img/001-dis-send-query.webp)
209209
![](./img/002-dis-merge-result.webp)
210210

211+
- MergeTree + Distributed 普通引擎 组合 分布式表引擎
212+
- ReplicatedMergeTree + Distributed 复制表引擎 组合 分布式表引擎
213+
211214
************************
212215
#
213216
> [doc: create table](https://clickhouse.com/docs/en/sql-reference/statements/create/table)

Database/OLAP/ClickhouseAdvance.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ categories:
1717
- 1.3. [存算分离](#存算分离)
1818
- 2. [使用实践](#使用实践)
1919
- 2.1. [写入](#写入)
20+
- 2.1.1. [同步写入](#同步写入)
2021
- 2.2. [查询](#查询)
2122
- 2.3. [监控](#监控)
2223

23-
💠 2025-03-07 10:54:31
24+
💠 2025-07-01 20:46:45
2425
****************************************
2526
# Clickhouse
2627

@@ -93,6 +94,25 @@ Spark 解析HDFS数据生成CK file(单个分区做一个gz压缩包,解压
9394
> [How to configure ClickHouse for INSERT performance? ](https://dev.to/shiviyer/how-to-configure-clickhouse-for-insert-performance-4cof)`大批量写入,异步写入,按需取消写入约束,表引擎调优,压缩算法替换,结合监控数据寻找出最合适业务数据的一套配置`
9495
> [Essential Monitoring Queries - part 1 - INSERT Queries](https://clickhouse.com/blog/monitoring-troubleshooting-insert-queries-clickhouse)
9596
97+
### 同步写入
98+
注意CK是最终一致性,所以修改不具备事务性,但是在特定业务场景如果需要依赖数据的有限一致性,可以通过设置一些参数值来靠拢
99+
100+
执行的insert SQL后追加 SETTINGS async_insert = 0;
101+
用户级设置 SETTINGS insert_quorum=2;
102+
会话设置:
103+
SET async_insert = 0; -- 关闭异步写入
104+
SET wait_for_async_insert = 1; -- 等待写入完成
105+
SET wait_for_insert_timeout = 10; -- 设置等待超时时间(秒)
106+
107+
缺点:
108+
写入延迟增加,因为需要等待数据落盘
109+
写入吞吐量下降,特别是在高并发场景
110+
可能影响查询性能,因为写入操作会占用更多系统资源
111+
112+
更高的 CPU 使用率
113+
更多的内存占用
114+
更频繁的磁盘 I/O 操作
115+
96116
## 查询
97117
不适合查单行的点查询, 最小查询数据量是索引粒度(index_granularity)的行数, 即使查询一条数据,CK也会按索引粒度加载整块数据进缓存
98118

0 commit comments

Comments
 (0)