tiflash在服务器负载极低的情况下, tiflash_wait: {pipeline_queue_wait: 5820ms}

【TiDB 使用环境】生产环境
一个tiflash节点,规格是 32c 64g 2t
在整体资源消耗极低的情况下(CPU 使用率1%都不到),执行计划出现了 tiflash_task:{time:5.89s, loops:80, threads:32}, tiflash_wait: {pipeline_queue_wait: 5820ms}。

tidb_max_tiflash_threads 使用的是默认值32

SELECT
  COUNT(*) AS total
FROM
  table_a tm
WHERE
  (
    tm.is_deleted = 0c
    AND tm.c_name LIKE concat('%', '圣', '%')
    AND tm.i_level IN ('N', 'H', 'A', 'B', 'C', 'O', 'D')
    AND tm.fail_status IN (0)
  )
  AND (
    tm.owner_id = ?
    AND tm.first_level_status NOT IN (0, 1)
    AND tm.created_org_id IN (?)
  );
| id                       | estRows | estCost      | actRows | task         | access object | execution info                | operator info                                                                                                                                                                                                                                                                                                                                                                                        
| StreamAgg_12             | 1.00    | 11060188.03  | 1       | root         |               | time:5.62s, loops:2 | funcs:count(1)->Column#99 
| └─TableReader_52         | 3.67    | 11060005.12  | 1       | root         |               | time:5.62s, loops:2, cop_task: {num: 2, max: 0s, min: 0s, avg: 0s, p95: 0s, copr_cache_hit_ratio: 0.00} | MppVersion: 2, data:ExchangeSender_51 
|   └─ExchangeSender_51    | 3.67    | 165899225.58 | 1       | mpp[tiflash] |               | tiflash_task:{time:5.62s, loops:1, threads:32}
|     └─Selection_50       | 3.67    | 165899225.58 | 1       | mpp[tiflash] |               | tiflash_task:{time:5.62s, loops:1, threads:32}
|       └─TableFullScan_49 | 4417.35 | 136629106.38 | 4611    | mpp[tiflash] | table:tm      | tiflash_task:{time:5.62s, loops:32, threads:32}, tiflash_wait: {pipeline_queue_wait: 5572ms}, tiflash_scan:{mvcc_input_rows:1710708, mvcc_input_bytes:29082036, mvcc_output_rows:1705959, lm_skip_rows:0, local_regions:8, remote_regions:0, tot_learner_read:4ms, region_balance:{instance_num: 1, max/min: 8/8=1.000000}, delta_rows:4537, delta_bytes:4388571, segments:5, stale_read_regions:0, tot_build_snapshot:0ms, tot_build_bitmap:79ms, tot_build_inputstream:81ms, min_local_stream:5601ms, max_local_stream:5602ms, dtfile:{data_scanned_rows:1697705, data_skipped_rows:44817, mvcc_scanned_rows:1706171, mvcc_skipped_rows:36351, lm_filter_scanned_rows:1742522, lm_filter_skipped_rows:0, tot_rs_index_check:0ms, tot_read:98ms}}
2 个赞

生产环境 TiFlash 资源空闲却任务慢,可能是pipeline 队列等待阻塞 。默认tidb_max_tiflash_threads=32 易导致线程竞争,建议下调至8-16 ,同时检查 TiFlash 节点的 pipeline 队列配置,避免资源空耗。

1 个赞

偶现问题,根据监控来看cup queue耗时严重。下调之后不是更容易发生竞争问题吗?

1 个赞

下调到 8-16 是适配实际任务的 “有效并行度”:既避免线程槽位闲置造成的调度内耗,又能让真正需要的线程高效利用 CPU,反而能缓解队列等待,不会加剧竞争。

参数:pipeline_task_threads`默认值:与tidb_max_tiflash_threads 联动(默认 32)调整建议:设为 8-16(和你下调后的tidb_max_tiflash_threads匹配,避免线程资源错配)。

资源空闲为什么pipeline 队列等待阻塞?是bug吗?

好的,谢谢。我试试效果,预发环境cpu是16c,配置为8是不是就可以了?

部分 TiFlash 版本存在 pipeline 队列调度的 BUG(如 <v5.4.0、v6.1.0 等),会导致任务在低负载下异常等待,即使资源充足也无法调度

我的版本是8.5.3

TiFlash 执行任务的「线程调度 / 队列阻塞」而非资源不足,默认配置下线程数(32)与任务调度机制不匹配,导致任务在队列中长时间等待,而非真正执行

没找到pipeline_task_threads参数,是profiles.default.max_threads吗?

可以解释一下为什么不匹配吗?针对不同的CPU核心数改如何配置?

可能是io瓶颈, 或多查询竞争tiflash线程池所致,建议先排查磁盘io性能和并发查询问题。

负载极低,cpu、内存、IO都极低,低到可以忽略

tidb_max_tiflash_threads 调整为16之后还是出现了这种问题
tiflash_task:{time:5.29s, loops:86, threads:16}, tiflash_wait: {pipeline_queue_wait: 5251ms}

max_pipeline_executor_threads tiflash侧这个参数跟 tidb_max_tiflash_threads保持一致

EXPLAIN ANALYZE 你的sql看下执行计划,大概率是pipeline final内部串行化了,concurrency=1,这是tiflash架构问题,只有优化sql或者多加几个节点去解决

看样子不像, final_worker:{wall_time:5.296102046s, concurrency:12, task_num:12, tot_wait:41.676µs, tot_exec:260ns, tot_time:1m3.552810498s, max:5.296089076s, p95:5.296089076s}

tot_wait:41.676µs, tot_exec:260ns 等待和单次执行都很快的,final_worker:{wall_time:5.296102046s 就是节点不够,mpp最终合并是需要串行化的

TableFullScan_45 | 18351.25 | 136290738.83 | 18496 | mpp[tiflash] | table:tm | tiflash_task:{time:5.29s, loops:86, threads:16}, tiflash_wait: {pipeline_queue_wait: 5251ms}

这是执行计划最底层的算子执行时间,我感觉瓶颈应该是在这里。目前就一个节点