History cache size-based limit charges proto wire size, so entries retain ~8x more heap than charged
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- go
- 領域
- backend, performance
調査の方向性
Start with ContextImpl.ApproximateSize() and the cache implementation under service/history/workflow/cache/. Review the reproduction tests in service/history/workflow/ and service/history/workflow/cache/, then run the commands given in the issue. Done means cache charging reflects the entries’ actual heap usage closely enough to satisfy the reproductions and the byte limit can reliably bound memory.
索引モデルが issue の本文から書いたものです。
説明
Expected Behavior and Actual Behavior
The history service keeps recently used workflows in an in-memory cache. With history.cacheSizeBasedLimit=true, the cache is limited by bytes instead of entry count, so history.hostLevelCacheMaxSizeBytes should roughly cap the memory the cache holds. This is not what is happening tho.
The cache charges each entry its serialized (protobuf) size, but an entry in memory is a Go object that takes much more heap than its serialized form. The extra cost grows with the number of items in the workflow (activities, timers, ...), not with their bytes.
So workflows made of many small items retain about 8x what they are charged, while workflows with large payloads are charged about right. Some experiments measured the following discrepancies:
| workflow shape | charged | heap retained | retained / charged |
|---|---|---|---|
| 200 activities | ~30 KB | ~256 KB | ~8.5x |
| 500 timers | ~18.5 KB | ~148 KB | ~8.0x |
| 1 activity with a 256 KiB payload | ~263 KB | ~270 KB | ~1.03x |
I measured per entry, not total process memory. Still, it means the byte limit can't be relied on to bound the cache's memory.
The charged size comes from ContextImpl.ApproximateSize(). Its doc comment already notes that in-memory size "will be slightly larger" than the serialized size; this shows it can be about 8x larger.
Steps to Reproduce the Problem
Two independent test-only PRs on my fork, each one test file, each expected to fail:
- Heap-based, https://github.com/MarcosCela/temporal/pull/5: compares the charged size with the live heap (GC-settled) held by N entries.
HISTORY_CACHE_SIZE_REPRO=1 go test -tags test_dep ./service/history/workflow/ -run TestHistoryCacheSizeRepro -v -count=1 - Reflection-based, https://github.com/MarcosCela/temporal/pull/6: fills the real workflow cache and compares its own
Size()with a reflection-based deep size of each entry, without using the GC.HISTORY_CACHE_SIZE_REPRO=1 go test -tags test_dep ./service/history/workflow/cache/ -run TestHistoryCacheDeepSizeRepro -v -count=1
Both fail when an entry is more than 2x its charged size, and are skipped without the environment variable.
Related reports
Similar symptoms (memory growing past the size-based limits); none identifies this cause:
- Forum thread: OOMs on v1.29.1 with both caches at 128 MB, stable when the mutable-state cache is count-based.
- #8902: history memory usage trend, same count-based workaround.
Other cacheSizeBasedLimit bugs, not this one: #10548, #9954, #9600.
Specifications
- Version:
mainat 873017418 (symptom also reported on 1.29.1 in the forum thread) - Platform: macOS arm64 and Linux arm64, Go 1.27.4
- 主要言語
- Go
- スター
- 24.7k
- フォーク
- 2.2k
- 平均マージ
- 3日 7時間
- マージ済み PR(30日)
- 222
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
temporalio/temporal のほかの issue
-
validate-dynamic-config always exits 0, even when it reports errors対応中かも @chanric が今日担当しました。 オープンenhancement oss-foundations
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
temporalio/temporal#13405 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
SQLite plugin treats SQLITE_BUSY and other unrelated errors as duplicate-key errors対応中かも @ratdaddy が 28 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
temporalio/temporal#12837 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
PostgreSQL buildDSN does not URL-encode cfg.User — usernames containing ":" (e.g. Vault dynamic credentials) break authentication対応中かも @jstar0 が 68 日前に担当しました。 オープンoss-foundations
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
temporalio/temporal#12192 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
RemoveSearchAttributes skips the secondary store under dual visibility対応中かも @breken-ai が 77 日前に担当しました。 オープンpotential-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
temporalio/temporal#12126 ·
メンテナーはふだん 1 日以内に返信
-
Expose `connectAttributes` to PostgreSQL対応中かも @downfa11 が 80 日前に担当しました。 オープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
temporalio/temporal#11780 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
temporalio/temporal の issue をすべて見る
似ている issue
-
bug effort:s impact:med raised-by:desk risk:low
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
medici-finance/assay#8342 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug sweep
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bketelsen/truenas-mcp#120 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nwverse/persona#22164 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sresarehumantoo/cc-artex#559 ·