Skip to content

[Performance] SQLFlusher trace/ETL path allocates heavily under high-concurrency sysbench workloads #25505

Closed

Description

@VioletQwQ-0

Summary

High-concurrency sysbench workloads show very large allocations from the trace/ETL SQLFlusher path. CPU cost is tiny (~0.006%), so this is not a direct CPU hotspot — the concern is allocation pressure and downstream GC overhead under high concurrency.

Workloads

  1. oltp_point_select --db-ps-mode=auto 1000vu (prepared)
  2. oltp_read_write 1000vu

Both on mo-srv-129 standalone (64-core, GOMEMLIMIT=40000MiB), main commit 2a008285e + closeTxn fix (#25490).

Profile Evidence

alloc_space top (30s sample):

workload SQLFlusher.FlushBuffer flat total alloc
point_select auto 1000vu 151.07GB (16.68%) 905.86GB
read_write 1000vu 156.35GB (9.90%) 1580.01GB

Call chain (cpu, focus FlushBuffer):

motrace.(*batchETLHandler).NewItemBatchHandler...
  → export.(*MOCollector).doExport
  → export.(*bufferExportReq).handle
  → export/etl.(*SQLFlusher).FlushBuffer

CPU cost is ~0.006% — the path spends almost no CPU, but allocates heavily for trace/ETL buffers.

read_write 1000vu GC rises to ~16% CPU (scanSpan 7.56% + tryDeferToSpanScan 5.20% + fpTracebackPartialExpand 3.25%), vs point_select's ~10%. The heavy allocation is a contributing factor.

Impact

Suggested Direction

  • Reuse buffers in SQLFlusher / MOCollector path.
  • Reduce per-statement trace allocation.
  • Consider sampling or high-concurrency degradation.
  • Verify with alloc_space and GC CPU before/after.

Reproduction

Profiles at mo-srv-129:/data/mo-prof/pprof/1000vu_auto/heap.pprof and mo-srv-129:/data/mo-prof/pprof_rw/1000vu/heap.pprof. Repro scripts /data/mo-prof/run_bench.sh (point_select) and /data/mo-prof/run_rw.sh (read_write). Related profiling task: #25472.

Activity

  1. self-assigned this
    on Jul 8, 2026
  2. VioletQwQ-0 commented on Jul 8, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    Follow-up: clean point_select + read_only/insert evidence

    After removing the read_write tombstone pollution from the point_select table, the clean point_select result improved significantly, but the SQLFlusher.FlushBuffer allocation issue still reproduces.

    Clean point_select, 8GB cache

    Workload: oltp_point_select, 1000vu, --db-ps-mode=auto (prepared), SHARED memory cache 8GB.

    • TPS: 150,941/s
    • avg latency: 6.61ms
    • p95: 27.17ms
    • heap alloc_space total: 4.62TB / 30s
    • SQLFlusher.FlushBuffer: 223.18GB flat / 225.06GB cum (4.87% cum)

    Line-level evidence:

    github.com/matrixorigin/matrixone/pkg/util/export/etl.(*SQLFlusher).FlushBuffer
      223.18GB flat / 225.06GB cum
    
    content.go:196  sqlCsv := bytes.NewBuffer(make([]byte, 0, table.DefaultWriterBufferSize))
    content.go:212  loadSQL := fmt.Sprintf(...)      1.25GB cum
    content.go:216  conn.Exec(loadSQL)              639MB cum
    

    This confirms the root cause is the fixed 10MB escape buffer per flush, not the SQL execution or formatting cost.

    Additional workloads

    SQLFlusher.FlushBuffer also appears consistently in read_only and insert profiles:

    workload total alloc SQLFlusher.FlushBuffer share
    read_only 500vu 7.65TB ~0.23TB cum 3.05%
    read_only 1000vu 7.07TB 230.25GB flat / 236.91GB cum 3.27%
    insert 500vu 8.67TB ~0.23TB cum 2.71%
    insert 1000vu 9.09TB 232.46GB flat / 240.73GB cum 2.59%

    For read_only/insert 1000vu, the same line accounts for nearly all SQLFlusher flat allocation:

    read_only 1000vu:
    content.go:196 fixed 10MB buffer: 230.25GB
    fmt.Sprintf:                         4.44GB
    conn.Exec:                           2.21GB
    
    insert 1000vu:
    content.go:196 fixed 10MB buffer: 232.46GB
    fmt.Sprintf:                         5.51GB
    conn.Exec:                           2.75GB
    

    Updated conclusion

    This is a cross-workload trace/ETL allocation issue. It is not specific to point_select, and it is independent of the earlier delete/tombstone pollution in the point_select table. The tombstone issue affects TPS/CPU/read-path attribution, but not this line-level SQLFlusher allocation root cause.

    Current fix direction

    Use the current batch size to construct the final LOAD DATA INLINE SQL directly, instead of allocating a fixed 10MB intermediate escape buffer per flush. The local candidate patch uses strings.Builder with exact Grow sizing based on:

    • original CSV length
    • number of escaped \ and ' bytes
    • SQL literal/table name overhead

    This removes both the fixed 10MB sqlCsv buffer and the extra fmt.Sprintf copy.

    Validation plan

    Use a clean point_select table/data set to avoid read_write delete tombstone pollution.

    Acceptance for the fix:

    • SQLFlusher.FlushBuffer drops from ~223GB alloc_space to GB-level or disappears from top20.
    • TPS and CPU do not regress on point_select clean auto 1000vu.
    • SQL escaping behavior remains unchanged (\ and ' are still escaped correctly).
  3. VioletQwQ-0 commented on Jul 8, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    Patch validation: clean point_select auto 1000vu

    Validated a local candidate fix on mo-srv-129 with a clean point_select dataset.

    Setup

    • Binary: patched mo-prof-svc with SQLFlusher.FlushBuffer changed to build the final LOAD DATA INLINE SQL directly via strings.Builder instead of allocating a fixed 10MB intermediate escape buffer.
    • Workload: oltp_point_select, 1000vu, --db-ps-mode=auto, --skip_trx=on, --point_selects=1
    • Data: fresh database sysbench_ps_sqlflusher_clean, 10 tables × 1M rows, prepared after service restart to avoid read_write delete/tombstone pollution.
    • FileService SHARED cache: 8GB memory + 50GB disk confirmed from startup log.
    • Profile path: mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu/

    Result

    metric clean baseline patched candidate
    TPS 150,941/s 169,974/s
    avg latency 6.61ms 5.87ms
    p95 latency 27.17ms 31.94ms
    CPU samples / 30s 1602.14s (~53.4 cores) 1620.27s (~54.0 cores)
    heap alloc_space total 4.62TB 506.39GB
    SQLFlusher.FlushBuffer 223.18GB flat / 225.06GB cum 0 flat / 30.54MB cum

    Line-level after patch

    github.com/matrixorigin/matrixone/pkg/util/export/etl.(*SQLFlusher).FlushBuffer
    Total heap alloc_space: 506.39GB
    
    FlushBuffer: 0 flat / 30.54MB cum (0.0059%)
    content.go:205 loadSQL.Grow(...)  15.87MB
    content.go:227 conn.Exec(...)     14.68MB
    

    SQLFlusher.FlushBuffer disappeared from top allocators. The fixed 10MB-per-flush allocation is removed.

    Notes

    • TPS and CPU did not regress; TPS improved in this run. p95 is higher than the previous clean baseline, so it should be watched in PR validation, but the primary allocation acceptance is met.
    • The large drop in total heap alloc_space also reflects that the previous fixed 10MB SQLFlusher buffer was a major allocation amplifier under high flush frequency.
  4. VioletQwQ-0 commented on Jul 13, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    Fixed by merged PR #25540: #25540. The fixed 10MB-per-flush SQLFlusher allocation was removed, with clean point_select validation showing SQLFlusher allocation dropping from ~223GB to MB-level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions