altinity-expert-clickhouse-caches
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCache Analysis and Tuning
缓存分析与调优
Analyze ClickHouse cache systems: mark cache, uncompressed cache, query cache, and compiled expression cache.
分析ClickHouse缓存系统:标记缓存、未压缩缓存、查询缓存和编译表达式缓存。
Diagnostics
诊断
Run all queries from the file checks.sql and analyze the results.
运行checks.sql文件中的所有查询并分析结果。
Cache Sizing Recommendations
缓存大小建议
| Cache | Typical Size | Notes |
|---|---|---|
| Mark Cache | 5-10% of RAM | Higher if random access patterns |
| Uncompressed | 0 (disabled) or 5-10% | Enable only for specific workloads |
| Query Cache | 1-5GB | For repeated identical queries |
| Compiled Expression | 128MB-1GB | Higher for complex expressions |
| 缓存类型 | 典型大小 | 说明 |
|---|---|---|
| 标记缓存 | 内存的5-10% | 如果是随机访问模式可设置更高 |
| 未压缩缓存 | 0(禁用)或内存的5-10% | 仅针对特定工作负载启用 |
| 查询缓存 | 1-5GB | 适用于重复的完全相同的查询 |
| 编译表达式缓存 | 128MB-1GB | 复杂表达式场景可设置更高 |
Problem Investigation
问题排查
Poor Mark Cache Hit Ratio
标记缓存命中率低
Possible causes:
- Cache too small for working set
- Queries scan many different tables
- Many small queries to cold data
可能原因:
- 缓存对于工作数据集来说太小
- 查询扫描多个不同的表
- 大量针对冷数据的小查询
Cache Too Large
缓存过大
If mark cache > 15% RAM:
Solutions:
- Reduce for tables with excessive marks
index_granularity - Drop unused tables
- Reduce setting
mark_cache_size
如果标记缓存占用内存超过15%:
解决方案:
- 针对标记过多的表减小
index_granularity - 删除未使用的表
- 减小设置
mark_cache_size
Cross-Module Triggers
跨模块触发条件
| Finding | Load Module | Reason |
|---|---|---|
| Cache using too much RAM | | Overall memory analysis |
| Poor hit ratio + high disk IO | | Disk bottleneck |
| Many marks per table | | Consider index_granularity tuning |
| Query cache misses | | Query pattern analysis |
| 发现的问题 | 加载模块 | 原因 |
|---|---|---|
| 缓存占用过多内存 | | 整体内存分析 |
| 命中率低 + 磁盘IO高 | | 磁盘瓶颈 |
| 每张表标记过多 | | 考虑调优index_granularity |
| 查询缓存未命中 | | 查询模式分析 |
Settings Reference
设置参考
| Setting | Scope | Notes |
|---|---|---|
| Server | Global mark cache limit |
| Server | Set to 0 to disable |
| Query | Enable per-query |
| Server | Query result cache |
| Query | Enable per-query |
| 设置项 | 作用范围 | 说明 |
|---|---|---|
| 服务器 | 全局标记缓存限制 |
| 服务器 | 设置为0以禁用 |
| 查询 | 按查询启用 |
| 服务器 | 查询结果缓存 |
| 查询 | 按查询启用 |