High memory usage (~14GB) when exporting large datasets (e.g. 2 million rows, ~700MB file)

オープン
#17,876 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
go, mysql

調査の方向性

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):

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bytebase/bytebase のほかの issue

bytebase/bytebase の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。