【TiDB 4.0 PCTA 学习笔记】- 3.7.2 The lifecycle of a SQL and relevant metrics(TiDB 的 SQL 的生命周期和关键监控指标)@3班+张近博

课程名称:课程版本(301)+ 3.7.2 The lifecycle of a SQL and relevant metrics(TiDB 的 SQL 的生命周期和关键监控指标)

学习时长:10分钟

课程收获:学习了通过dumpling导出数据并由lightning导入数据

课程内容:

  1. SQL在TiDB中的流程

    1) 执行之前有两个步骤
    A) Get token
    Token用于限制SQL数,防止TiDB挂掉,配置参数是token-limit
    B) Get TSO
    开始和提交事务都会像PD请求TSO,这个步骤是异步的,PD TSO Wait Duration高意味着TiDB自己负载高,PS TSO RPC Duration高意味着TiDB和PD直接延迟高或者PD负载高
    2) 解析和编译阶段
    A) Parse: Dashboard和Grafana: Parse duration都可以看出耗时
    B) Compile: Dashboard和Grafana: Compile duration都可以看出耗时
    C) Prepared Statements: 节省解析时间,通过Grafana: Prepare Statement count查看
    D) Prepared Plan Cache: 节省优化时间,通过Grafana: Plan Cache Hits查看
    3) 执行阶段
    A) Execution Duration:
    B) Expensive Executors OPS
    C) KV Request: KV Request Duration 99/TiClient Region Error OPS/Lock Resolve OPS
  1. 事务阶段
    A) KV Transaction Duration
    B) Local Latch: TiDB在prewriting之前等待内存锁,Grafana: Local Latch Wait Time
    C) Transaction Retry: 错误较多是会重试, Grafana : Transaction Retry Num
  1. SQL在TiKV的流程

    1) KV Request
    gRPC Message duration
    A) kv_get/kv_batch_get/coprocessor
    B) KV Duration in TiDB ~= gRPC Message duration + network RTT
  1. Transaction
    A) Prewrite & Commit: Dashboard中查看
    B) Resolve lock:Dashboard和Grafana: Lock Resolve OPS查看
    3)Raft Store
    A) Raft Propose: Propose wait duration和 Apply wait duration
    B) Raft IO: Append log duration/ Apply log duration Commit/ log duration
  2. Coprocessor
    A) Coprocessor Execution Time: Dashboard和Grafana: Request Duration查看
    B) Coprocessor Wait Time: Dashboard和Grafana: Wait Duration查看,如果等待时间高,可以尝试打开Coprocessor Cache

3.RocksDB:每个TiKV有两个RocksDB实例用来存储Raft和KV
2-3