Repository navigation
perf(trace): reduce SQLFlusher inline SQL allocation - #25540
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
gouhongshen
left a comment
There was a problem hiding this comment.
Reviewed the allocation change in SQLFlusher.FlushBuffer.
No blocking issues found. The new builder path preserves the byte-level escaping behavior for \ and ', removes the fixed 10MB intermediate buffer, and leaves the existing file-flush-on-SQL-error path unchanged. PR scope is clean (content.go / content_test.go only), and GitHub checks are green.
Local note: I could not rerun go test ./pkg/util/export/etl/... on this workstation because the MatrixOne third-party cgo headers (xxhash.h, roaring.h, usearch.h) are missing here; the corresponding GitHub UT check passed.
|
Queued — the merge queue status continues in this comment ↓. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed this from correctness, unhappy-path behavior, and the specific allocation goal of #25505.
I checked the main risk points:
- escaping semantics for
\and'stayed identical while removing the fixed 10MB intermediate buffer - the final SQL shape is unchanged except for the allocation strategy
- failure/backoff / reconnect paths in
FlushBufferare untouched - the added regression test covers the inline escaping case that is easiest to break in this refactor
I don't see a blocking issue in this change set. Approving.
) `SQLFlusher.FlushBuffer` used to allocate a fixed `table.DefaultWriterBufferSize` 10MB intermediate buffer for every trace/ETL SQL flush before building the final `LOAD DATA INLINE` statement. Under high-concurrency sysbench workloads this became a large allocation amplifier even when the actual CSV batch was much smaller than 10MB. This PR builds the final inline SQL directly with `strings.Builder` and sizes it from the actual batch length plus the number of bytes that need SQL escaping. This removes the fixed 10MB intermediate buffer and avoids the extra `fmt.Sprintf` copy. Changes: - Replace the fixed 10MB `sqlCsv` buffer in `SQLFlusher.FlushBuffer` with an exactly-sized `strings.Builder` for the final SQL. - Preserve the existing escape behavior for `\` and `'`. - Add a regression test for inline SQL escaping. Validation: - `go test ./pkg/util/export/etl/...` - mo-srv-129 clean point_select validation, 1000vu, `--db-ps-mode=auto`, 8GB SHARED cache, fresh `sysbench_ps_sqlflusher_clean` database: | metric | clean baseline | patched run 1 | patched run 2 | |---|---:|---:|---:| | TPS | 150,941/s | 169,974/s | 161,550/s | | avg latency | 6.61ms | 5.87ms | 6.18ms | | p95 latency | 27.17ms | 31.94ms | 27.17ms | | CPU samples / 30s | 1602.14s (~53.4 cores) | 1620.27s (~54.0 cores) | 1604.88s (~53.5 cores) | | heap alloc_space total | 4.62TB | 506.39GB | 1019.38GB | | `SQLFlusher.FlushBuffer` | 223.18GB flat / 225.06GB cum | 0 flat / 30.54MB cum | 0 flat / 77.48MB cum | Note: Go heap `alloc_space` is cumulative since process start. Patched run 2 reused the same patched MO process after run 1, so its heap total includes prior allocations. It is included as a stability check that `SQLFlusher.FlushBuffer` remains MB-level after another 1000vu run. Profile paths: - baseline: `mo-srv-129:/data/mo-prof/pprof/1000vu_clean_auto/` - patched run 1: `mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu/` - patched run 2: `mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu_rerun/` Approved by: @gouhongshen, @XuPeng-SH
) `SQLFlusher.FlushBuffer` used to allocate a fixed `table.DefaultWriterBufferSize` 10MB intermediate buffer for every trace/ETL SQL flush before building the final `LOAD DATA INLINE` statement. Under high-concurrency sysbench workloads this became a large allocation amplifier even when the actual CSV batch was much smaller than 10MB. This PR builds the final inline SQL directly with `strings.Builder` and sizes it from the actual batch length plus the number of bytes that need SQL escaping. This removes the fixed 10MB intermediate buffer and avoids the extra `fmt.Sprintf` copy. Changes: - Replace the fixed 10MB `sqlCsv` buffer in `SQLFlusher.FlushBuffer` with an exactly-sized `strings.Builder` for the final SQL. - Preserve the existing escape behavior for `\` and `'`. - Add a regression test for inline SQL escaping. Validation: - `go test ./pkg/util/export/etl/...` - mo-srv-129 clean point_select validation, 1000vu, `--db-ps-mode=auto`, 8GB SHARED cache, fresh `sysbench_ps_sqlflusher_clean` database: | metric | clean baseline | patched run 1 | patched run 2 | |---|---:|---:|---:| | TPS | 150,941/s | 169,974/s | 161,550/s | | avg latency | 6.61ms | 5.87ms | 6.18ms | | p95 latency | 27.17ms | 31.94ms | 27.17ms | | CPU samples / 30s | 1602.14s (~53.4 cores) | 1620.27s (~54.0 cores) | 1604.88s (~53.5 cores) | | heap alloc_space total | 4.62TB | 506.39GB | 1019.38GB | | `SQLFlusher.FlushBuffer` | 223.18GB flat / 225.06GB cum | 0 flat / 30.54MB cum | 0 flat / 77.48MB cum | Note: Go heap `alloc_space` is cumulative since process start. Patched run 2 reused the same patched MO process after run 1, so its heap total includes prior allocations. It is included as a stability check that `SQLFlusher.FlushBuffer` remains MB-level after another 1000vu run. Profile paths: - baseline: `mo-srv-129:/data/mo-prof/pprof/1000vu_clean_auto/` - patched run 1: `mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu/` - patched run 2: `mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu_rerun/` Approved by: @gouhongshen, @XuPeng-SH
) `SQLFlusher.FlushBuffer` used to allocate a fixed `table.DefaultWriterBufferSize` 10MB intermediate buffer for every trace/ETL SQL flush before building the final `LOAD DATA INLINE` statement. Under high-concurrency sysbench workloads this became a large allocation amplifier even when the actual CSV batch was much smaller than 10MB. This PR builds the final inline SQL directly with `strings.Builder` and sizes it from the actual batch length plus the number of bytes that need SQL escaping. This removes the fixed 10MB intermediate buffer and avoids the extra `fmt.Sprintf` copy. Changes: - Replace the fixed 10MB `sqlCsv` buffer in `SQLFlusher.FlushBuffer` with an exactly-sized `strings.Builder` for the final SQL. - Preserve the existing escape behavior for `\` and `'`. - Add a regression test for inline SQL escaping. Validation: - `go test ./pkg/util/export/etl/...` - mo-srv-129 clean point_select validation, 1000vu, `--db-ps-mode=auto`, 8GB SHARED cache, fresh `sysbench_ps_sqlflusher_clean` database: | metric | clean baseline | patched run 1 | patched run 2 | |---|---:|---:|---:| | TPS | 150,941/s | 169,974/s | 161,550/s | | avg latency | 6.61ms | 5.87ms | 6.18ms | | p95 latency | 27.17ms | 31.94ms | 27.17ms | | CPU samples / 30s | 1602.14s (~53.4 cores) | 1620.27s (~54.0 cores) | 1604.88s (~53.5 cores) | | heap alloc_space total | 4.62TB | 506.39GB | 1019.38GB | | `SQLFlusher.FlushBuffer` | 223.18GB flat / 225.06GB cum | 0 flat / 30.54MB cum | 0 flat / 77.48MB cum | Note: Go heap `alloc_space` is cumulative since process start. Patched run 2 reused the same patched MO process after run 1, so its heap total includes prior allocations. It is included as a stability check that `SQLFlusher.FlushBuffer` remains MB-level after another 1000vu run. Profile paths: - baseline: `mo-srv-129:/data/mo-prof/pprof/1000vu_clean_auto/` - patched run 1: `mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu/` - patched run 2: `mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu_rerun/` Approved by: @gouhongshen, @XuPeng-SH
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25505
What this PR does / why we need it:
SQLFlusher.FlushBufferused to allocate a fixedtable.DefaultWriterBufferSize10MB intermediate buffer for every trace/ETL SQL flush before building the finalLOAD DATA INLINEstatement. Under high-concurrency sysbench workloads this became a large allocation amplifier even when the actual CSV batch was much smaller than 10MB.This PR builds the final inline SQL directly with
strings.Builderand sizes it from the actual batch length plus the number of bytes that need SQL escaping. This removes the fixed 10MB intermediate buffer and avoids the extrafmt.Sprintfcopy.Changes:
sqlCsvbuffer inSQLFlusher.FlushBufferwith an exactly-sizedstrings.Builderfor the final SQL.\and'.Validation:
go test ./pkg/util/export/etl/...--db-ps-mode=auto, 8GB SHARED cache, freshsysbench_ps_sqlflusher_cleandatabase:SQLFlusher.FlushBufferNote: Go heap
alloc_spaceis cumulative since process start. Patched run 2 reused the same patched MO process after run 1, so its heap total includes prior allocations. It is included as a stability check thatSQLFlusher.FlushBufferremains MB-level after another 1000vu run.Profile paths:
mo-srv-129:/data/mo-prof/pprof/1000vu_clean_auto/mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu/mo-srv-129:/data/mo-prof/pprof/sqlflusher_clean_auto_1000vu_rerun/