fix: clear user sessions between load stages#459
Merged
achandrasekar merged 1 commit intoApr 29, 2026
Merged
Conversation
LocalUserSession._instances was never cleared between stages, causing session context to accumulate across stage boundaries and prompts to grow indefinitely in multi-turn shared-prefix workloads. Non-mp path (num_workers=0): call LocalUserSession.clear_instances() between stages in LoadGenerator.run(). Mp path (num_workers>0): add an mp.Barrier to synchronize workers and main at stage boundaries. Workers finish in-flight requests, clear sessions, then wait at the barrier. Main waits at the barrier after request_queue.join(), ensuring all workers have cleaned up before the next stage begins. Without the barrier, request_phase can be cleared and re-set before workers notice, causing them to miss the stage boundary entirely.
Contributor
|
/lgtm |
Contributor
|
/approve Thanks for fixing this! |
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: achandrasekar, alonh The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
jjk-g
pushed a commit
to jjk-g/inference-perf
that referenced
this pull request
Apr 30, 2026
## Summary - `LocalUserSession._instances` was never cleared between load stages, causing session context to accumulate across stage boundaries and prompts to grow indefinitely in multi-turn shared-prefix workloads. - **Non-mp path** (`num_workers=0`): call `LocalUserSession.clear_instances()` between stages in `LoadGenerator.run()`. - **Mp path** (`num_workers>0`): add an `mp.Barrier` to synchronize workers and main at stage boundaries. Workers finish in-flight requests, clear sessions, then wait at the barrier. Main waits after `request_queue.join()`, ensuring all workers have cleaned up before the next stage begins. Without the barrier, `request_phase` can be cleared and re-set before workers notice, causing them to miss the stage boundary entirely. ## Test plan - [x] Unit tests for `LocalUserSession.clear_instances()` (singleton reset, context reset) - [x] Integration test: non-mp LoadGenerator with two stages verifies stage 1 prompts contain no stage 0 context - [x] Integration test: mp LoadGenerator (`num_workers=1`) with two stages verifies stage 1 prompts contain no stage 0 context via mp.Queue - [x] mypy --strict passes - [x] All 5 tests pass reliably across 10 consecutive runs Fixes kubernetes-sigs#447 Fixes kubernetes-sigs#444
kaushikmitr
added a commit
to kaushikmitr/inference-perf
that referenced
this pull request
May 3, 2026
When LoadGenerator clears LocalUserSession._instances between load stages (PR kubernetes-sigs#459), conversation_replay's user_sessions[].user_session_id no longer resolves in the registry. The next get_instance() lazily creates a fresh session with empty context, dropping the per-conversation system_prompt and producing dramatically smaller prompts in stages 1+. Detect the cleared registry at the top of load_lazy_data and re-register the session with its original system_prompt before dispatching.
achandrasekar
pushed a commit
that referenced
this pull request
May 5, 2026
When LoadGenerator clears LocalUserSession._instances between load stages (PR #459), conversation_replay's user_sessions[].user_session_id no longer resolves in the registry. The next get_instance() lazily creates a fresh session with empty context, dropping the per-conversation system_prompt and producing dramatically smaller prompts in stages 1+. Detect the cleared registry at the top of load_lazy_data and re-register the session with its original system_prompt before dispatching.
kaushikmitr
added a commit
to kaushikmitr/inference-perf
that referenced
this pull request
May 6, 2026
The barrier added in kubernetes-sigs#459 (clear user sessions between stages) requires all N+1 parties (N workers + parent) to arrive before any can proceed. With no timeout, a single worker stuck in gather() — e.g., waiting on an in-flight request that never completes — leaves the rest of the cluster hanging forever. Multi-stage benchmark runs reproduce this: stages all dispatch cleanly, then everyone hangs in epoll_wait, no error, no progress. Bound both the worker-side and parent-side barrier waits with a 600s timeout. On timeout, BrokenBarrierError surfaces; we log a warning and proceed. Healthy workers + parent move on; the stuck worker eventually gets terminated by loadgen.stop() at job teardown.
kaushikmitr
added a commit
to kaushikmitr/inference-perf
that referenced
this pull request
May 6, 2026
The barrier added in kubernetes-sigs#459 (clear user sessions between stages) requires all N+1 parties (N workers + parent) to arrive before any can proceed. With no timeout, a single worker stuck in gather() — e.g., waiting on an in-flight request that never completes — leaves the rest of the cluster hanging forever. Multi-stage benchmark runs reproduce this: stages all dispatch cleanly, then everyone hangs in epoll_wait, no error, no progress. Bound both the worker-side and parent-side barrier waits with a 600s timeout. On timeout, BrokenBarrierError surfaces; we log a warning and proceed. Healthy workers + parent move on; the stuck worker eventually gets terminated by loadgen.stop() at job teardown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LocalUserSession._instanceswas never cleared between load stages, causing session context to accumulate across stage boundaries and prompts to grow indefinitely in multi-turn shared-prefix workloads.num_workers=0): callLocalUserSession.clear_instances()between stages inLoadGenerator.run().num_workers>0): add anmp.Barrierto synchronize workers and main at stage boundaries. Workers finish in-flight requests, clear sessions, then wait at the barrier. Main waits afterrequest_queue.join(), ensuring all workers have cleaned up before the next stage begins. Without the barrier,request_phasecan be cleared and re-set before workers notice, causing them to miss the stage boundary entirely.Test plan
LocalUserSession.clear_instances()(singleton reset, context reset)num_workers=1) with two stages verifies stage 1 prompts contain no stage 0 context via mp.QueueFixes #447
Fixes #444