# [Know Issue] TiCDC 同步存在延迟

## Key Words

TiCDC, 同步延迟

## Description

TiCDC 存在同步延迟，通过监控发现 changefeed checkpoint 推进非常缓慢，并且 sorter input/output 存在巨大的差距，但是通过监控 "Processor Memory Consumption Per Capture" 展示 changefeed 没有达到参数 `per-table-memory-quota` 的限制（默认 10M）。但是通过抓取的 TiCDC 堆栈信息展示：

```log
goroutine 5663 [sync.Cond.Wait, 168 minutes]:
sync.runtime_notifyListWait(0xc00556cfd0, 0x0)
    runtime/sema.go:513 +0xf8
sync.(*Cond).Wait(0xc00556cfc0)
    sync/cond.go:56 +0x99
github.com/pingcap/tiflow/cdc/sink/common.(*TableMemoryQuota).ConsumeWithBlocking(0xc00b2a9680, 0x4b8, 0xc05dc80390, 0x0, 0x0)
    github.com/pingcap/tiflow/cdc/sink/common/flow_control.go:85 +0xcf
github.com/pingcap/tiflow/cdc/sink/common.(*TableFlowController).Consume(0xc00b2a96b0, 0x60d1acc4f780014, 0x4b8, 0xc05dc80390, 0x0, 0x0)
    github.com/pingcap/tiflow/cdc/sink/common/flow_control.go:177 +0x99
github.com/pingcap/tiflow/cdc/processor/pipeline.(*sorterNode).Init.func4(0x0, 0x0)
    github.com/pingcap/tiflow/cdc/processor/pipeline/sorter.go:151 +0x551
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc00aa23008, 0xc00a0f5f00)
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:57 +0x59
created by golang.org/x/sync/errgroup.(*Group).Go
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:54 +0x66
```

## Root Cause

单表事务过大时，可能会遇到单表处理 event 的内存超过 per-table-memory-quota 限制触发流控，监控 "Processor Memory Consumption Per Capture" 指标存在统计[不准确的问题](https://github.com/pingcap/tiflow/issues/7217)。

## Diagnostic Steps

1. 监控指标 sorter input/output 存在大的差异。
2. 上游 TiKV CPU 使用率正常，resolvedTs lag 正常，但是日志有很多 resolvedTs is fallen back in kvclient 相关信息打印。
3. 下游写入没有很明显的延迟。
4. 监控指标 "Processor Memory Consumption Per Capture" 没有超过`per-table-memory-quota` 的限制（默认 10M）。
5. 抓取 TiCDC 堆栈信息 `http://$(cdc-ip):$(cdc-port)/debug/pprof/goroutine?debug=2` 显示存在流控。

## Resolution

升级到 v6.2.0 及以上版本

## Workaround

调大流控触发阈值 per-table-memory-quota（默认 10M），可以缓解 TiCDC 延迟程度。

## Affected Versions

<v6.1.0
