课程名称:3.7.2 TiDB 的 SQL 的生命周期和关键监控指标
学习时长:20min
课程收获:SQL 生命周期中的各个阶段,以及通过 Dashboard 和 Grafana 定位问题的方法
课程内容:
- SQL在TiDB中的流程
* 开启Prepared Statement会略过Parse和Preprocess
* 开启Prepared Plan Cache会略过Parse、Preprocess、Logic Optimizer和Physical Optimizer- 获取Token
- Token是用于限制SQL并发
- 配置:
token-limit
- Grafana:Get Token Duration
- Get TSO
- 异步地从PD获取时间戳(开始事务和结束事务都要获取)
- Dashboard(SQL Statements & Slow Query)
- Grafana:PD TSO Wait Duration(说明TiDB负载)
- Grafana:PD TSO RPC Duration(说明TiDB于PD之间的网络情况或这PD负载)
- Parse
Dashboard(SQL Statements & Slow Query)
Grafana:Parse Duration
一般batch insert时会耗时高 - Compile
- Preprocess(validator & type infer)+ Optimize
- Dashboar(SQL Statements & Slow Query)
- Grafana:Compile Duration
- 一般在复杂查询时耗时高
- Prepared Statements
- 可以节省解析和预处理的开销
- Grafana:Prepare Statement Count
- Prepared Plan Cache
- 节省优化的开销
- Grafana:Plan Cache Hits
- 执行阶段
- Execution Duration
- Expensive Executors OPS
- HashAgg / Sort /IndexLookUp…
- 相关系统变量
tidb_{operator}_concurrency
- KV Request
- KV Request Duration 99
- TiClient Region Error OPS
- Lock Resolve OPS
- DistSQL
- 发送KV请求及接收KV结果
- DistSQL Duration
- 并发发送请求
- 控制并发度:
tidb_distsql_scan_concurrency
- Scan Keys
- Dashboard(SQL Statements & Slow Query)
- Grafana:Scan Keys
- Coprocessor & Get & Batch Get
- KV Request OPS
- 事务
- KV Transaction Duration
- Local Latch
- 适合冲突高的场景,默认关闭
- Dashboard(SQL Statements & Slow Query)
- Grafana:Local Latch Wait Time
- Transaction Retry
- 像写冲突等之类的错误是可以重试的
- Dashboard(SQL Statements & Slow Query)
- Grafana:Transaction Retry Num
- 获取Token
- SQL在TiKV中的流程
- KV Request
- gRPC Message Duration(反映TiKV中时间开销)
- kv_get /kv_batch_get / coprocessor
- KV Duration in TiDB ~= gRPC Message Duration + network RTT
- gRPC Message Duration(反映TiKV中时间开销)
- 事务
- Prewrite & Commit
- Dashboard(SQL Statements & Slow Query)
- Resolve Lock
- Dashboard(SQL Statements & Slow Query)
- Lock Resolve OPS
- Prewrite & Commit
- Raft Store
- 使用Raft协议来保证副本的一致性
- Raft propose
- Propose wait duration
- Apply wait duration
- Raft IO
- Append log duration
- Apply log duration
- Commit log duration
- Coprocessor
- Corprocessor Execution Time
- Dashboard(SQL Statements & Slow Query)
- Request Duration
- Coprocesor Wait Time
- Dashboard(SQL Statements & Slow Query)
- Wait Duration
- 可以通过coprocessor cache来优化
- Corprocessor Execution Time
- RocksDB
- 每个TiKV实例都有两个RocksDB实例
- Raft:存储Raft日志
- KV:存储用户数据
- Read
- Get/Seek duration
- Memtable hit
- Block cache hit
- SST read duration
- Write
- Write duration
- Compaction
- Compaction operations
- Compaction duration
- 每个TiKV实例都有两个RocksDB实例
- KV Request