Skip to content

compose.ymlのPSQLサイドカーにメモリチューニング設定を追加#1527

Merged
TinyKitten merged 1 commit into
devfrom
chore/compose-psql-memory-tuning
May 16, 2026
Merged

compose.ymlのPSQLサイドカーにメモリチューニング設定を追加#1527
TinyKitten merged 1 commit into
devfrom
chore/compose-psql-memory-tuning

Conversation

@TinyKitten
Copy link
Copy Markdown
Member

@TinyKitten TinyKitten commented May 16, 2026

概要

ローカル開発用 compose.yml の PostgreSQL サイドカーに shared_buffers / work_mem / maintenance_work_mem / effective_cache_size のメモリ系チューニング設定を追加。

変更の種類

  • バグ修正
  • 新機能
  • データの修正・追加
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • compose.ymlpsql サービスに command を追加し、PostgreSQL の以下のメモリパラメータをデフォルトから引き上げ
    • shared_buffers=384MB(デフォルト 128MB): 内部ページキャッシュ
    • work_mem=64MB(デフォルト 4MB): ソート/ハッシュ結合/集約あたりの上限
    • maintenance_work_mem=256MB(デフォルト 64MB): ANALYZE / CREATE INDEX / VACUUM のワークメモリ
    • effective_cache_size=1GB: プランナーへの実効キャッシュサイズのヒント
  • 動機: ECS 本番タスクでメモリ利用率が 14〜19% 程度で大半が遊んでいたため、サイドカー PSQL がリソースをより活用できるよう調整。build_stop_route_mappingintegrate_gtfs_trip_variations_to_types の重い CTE クエリ・起動時の ANALYZE 速度・ランタイムの JOIN/ソート性能改善を狙う
  • ローカル dev 環境用の設定値。本番 ECS のタスク定義側にも同じ値を当てる前提(タスク定義は repo 外)

テスト

  • cargo fmt --all -- --check が通ること
  • cargo clippy -- -D warnings が通ること
  • cargo test(SQLX_OFFLINE=true)が通ること

docker compose up で立ち上げて SHOW work_mem; 等で反映確認可能。

関連Issue

スクリーンショット(任意)

Summary by CodeRabbit

  • Chores
    • PostgreSQL データベースサービスの構成を更新しました。メモリ管理に関連する複数の新しいパラメータが追加され、サービス起動時に自動的に適用されるようになります。追加される設定項目は shared_bufferswork_memmaintenance_work_memeffective_cache_size です。既存の環境設定への影響はありません。

Review Change Stack

ECSメトリクスでタスク全体のメモリ使用率が2GB中380MB(19%)程度に留まり
リソースが遊んでいたため、PostgreSQLが使えるメモリを引き上げる。

- shared_buffers: 128MB → 384MB (ページキャッシュ拡大)
- work_mem: 4MB → 64MB (ソート/ハッシュ結合のスピル抑制)
- maintenance_work_mem: 64MB → 256MB (ANALYZE/CREATE INDEXの高速化)
- effective_cache_size: 4GB → 1GB (プランナーへの実態に即したヒント)

UNLOGGEDテーブル運用なのでshared_buffersの効果が通常より大きい。
maintenance_work_memの引き上げはデプロイ時の起動時間短縮に直結する。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TinyKitten TinyKitten self-assigned this May 16, 2026
@github-actions github-actions Bot added chore ちょっとした変更 deploy-dev and removed chore ちょっとした変更 labels May 16, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

📝 Walkthrough

Walkthrough

compose.ymlpsql サービスに PostgreSQL の起動時パラメータ設定を追加しました。shared_bufferswork_memmaintenance_work_memeffective_cache_size-c オプションで指定し、メモリ関連のパフォーマンス設定をコンテナ起動時に適用するようにしました。

Changes

PostgreSQL パフォーマンス設定

Layer / File(s) Summary
psql サービス起動パラメータ設定
compose.yml
psql サービスに command フィールドを追加し、PostgreSQL メモリ関連設定(shared_bufferswork_memmaintenance_work_memeffective_cache_size)を起動引数として指定。

🎯 1 (Trivial) | ⏱️ ~3 minutes

🐰 メモリ設定を整える兎
パラメータ並べて、PostgreSQL 元気に
shared_buffers が増えて、ぴょんぴょん加速!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PRタイトルは、compose.ymlのPSQLサービスにメモリチューニング設定を追加するというPRの主な変更内容を的確に要約しており、簡潔で明確です。
Description check ✅ Passed PR説明は必須セクション(概要、変更の種類、変更内容、テスト、関連Issue)をすべて記載し、詳細で具体的な情報を含んでいます。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/compose-psql-memory-tuning

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@compose.yml`:
- Line 30: The global PostgreSQL setting work_mem=64MB is too high and risks OOM
under concurrent load; change the compose.yml default to a safer lower value
(e.g., work_mem=16MB or 4-32MB range) and document/instrument the repo to raise
work_mem only for heavy queries using SET LOCAL work_mem or
per-role/per-connection configuration; update the compose.yml entry for work_mem
and add a short note in your DB runbook or comments explaining to use SET LOCAL
work_mem for intensive operations or connection-role specific overrides.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a56d657-2618-4a5e-90c0-2db5bfc7212a

📥 Commits

Reviewing files that changed from the base of the PR and between d854d6e and 41f089c.

📒 Files selected for processing (1)
  • compose.yml

Comment thread compose.yml
@TinyKitten TinyKitten merged commit e046955 into dev May 16, 2026
3 checks passed
@TinyKitten TinyKitten deleted the chore/compose-psql-memory-tuning branch May 16, 2026 01:18
@TinyKitten TinyKitten mentioned this pull request May 17, 2026
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant