High memory usage (~14GB) when exporting large datasets (e.g. 2 million rows, ~700MB file)
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- go, mysql
- 領域
- backend, database, performance
調査の方向性
backend/runner/taskrun/data_export_executor.go の DoExport から始めて exportCSV を追跡し、issue に記載されている結果セット全体の実体化と bytes.Buffer のアロケーションに注目します。issue で報告されている 2-million-row、~700 MB のデータセットのような大規模なエクスポートをプロファイリングし、メモリ内バッファリングを最小限にしてエクスポート後にデータを解放することで、メモリ使用量が削減されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Is your feature request related to a problem?
Yes. When using the Export Center to export a large dataset (around 2 million rows, ~700MB file), Bytebase’s memory usage spikes to around 14GB.
Describe the solution you'd like
I hope the export mechanism can be optimized to use memory more efficiently.
During large data exports, Bytebase should minimize in-memory buffering and promptly release memory once the export is finished.
Additional context
Environment:
- Bytebase Version: 3.11.0
- Database: MySQL 5.7.30
- Deployment Binary: Mac
Observed memory usage: ~14GB during export. mem.log
Suggest adding monitoring or log tracing for export performance.
- export data list
-rw-r--r--@ 1 mako staff 689M Oct 28 15:30 test.csv
-rw-r--r--@ 1 mako staff 41M Oct 28 15:30 export-data-2025-10-28T15-30-38.zip
- monitor shell
while ps -p "$PID" >/dev/null 2>&1; do
ts=$(date '+%Y-%m-%d %H:%M:%S')
line=$(top -l 1 -pid $PID -stats pid,cpu,mem | awk -v pid=$PID '$1==pid {print}')
if [ -z "$line" ]; then
sleep 2
continue
fi
pid_val=$(echo $line | awk '{print $1}')
cpu_val=$(echo $line | awk '{print $2}')
mem_str=$(echo $line | awk '{print $3}')
if [[ $mem_str == *G ]]; then
mem_val=$(awk -v m="${mem_str%G}" 'BEGIN{printf "%.1f", m*1024}')
elif [[ $mem_str == *M ]]; then
mem_val=$(awk -v m="${mem_str%M}" 'BEGIN{printf "%.1f", m}')
else
mem_val=0
fi
output="$ts $pid_val $cpu_val $mem_val"
echo "$output"
sleep 2
done
Below is a memory usage analysis captured during one large export task (~2 million rows, ~700 MB data):
- Key Observations
DoExport
| Stage | Alloc (GB) | HeapInuse (GB) | Delta (GB) | Notes |
|---|---|---|---|---|
| DoExport:begin | 0.23 | 0.27 | — | Initial baseline |
| DoExport:beforeEncode | 8.29 | 8.49 | +8.06 | Materializing full result set into memory |
| exportCSV:end | 11.73 | 11.87 | +3.44 | CSV encoding via bytes.Buffer causes large temporary allocations |
| doEncrypt:end | 4.38 | 4.38 | +0.13 | Minor additional cost during encryption/compression |
- Detailed Findings
• Result set fully materialized: the entire query result is held in memory (v1pb.QueryResult → Rows → Values), including desensitized copies.
• Encoding stage is the main source of memory growth: exportCSV constructs the full file in memory using bytes.Buffer, repeatedly expanding and copying data.
• Compression/encryption overhead is minimal in comparison.
• GC didn’t trigger during CSV encoding, likely because large objects remained referenced.
• In XLSX exports (not sampled here), memory use is typically even higher, since excelize keeps a full workbook model plus a final ZIP buffer in memory simultaneously.
- 主要言語
- Go
- スター
- 14.5k
- フォーク
- 984
- 平均マージ
- 15時間 58分
- マージ済み PR(30日)
- 256
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bytebase/bytebase のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
bytebase/bytebase の issue をすべて見る
似ている issue
-
optimization optimization:agents-md-curator
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
githubnext/gh-aw-cao#13143 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
blinklabs-io/bursa#904 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · コメント 2 件 ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100