Skip to content

perf(session): shard the in-memory session store lock#154

Open
SVilgelm wants to merge 2 commits into
rust-mcp-stack:mainfrom
SVilgelm:perf/session-store-sharding
Open

perf(session): shard the in-memory session store lock#154
SVilgelm wants to merge 2 commits into
rust-mcp-stack:mainfrom
SVilgelm:perf/session-store-sharding

Conversation

@SVilgelm
Copy link
Copy Markdown
Contributor

📌 Summary

The in-memory session store guarded every operation with a single global RwLock, serializing the dispatch path under many concurrent clients. Sessions are now spread across 16 independently locked shards so requests for different sessions rarely contend. The SessionStore trait surface is unchanged.

Stacked on #152 — review/merge that first; the diff specific to this PR is the sharded store.

🔍 Related Issues

✨ Changes Made

  • Replace the global RwLock<HashMap> with a 16-way sharded map keyed by session-id hash.
  • Spread get/set/delete/has across shards; aggregate keys/values/eviction across all shards.

SVilgelm added 2 commits May 25, 2026 12:11
Add a max-session cap (default 10k) and optional idle TTL with lazy eviction. New sessions past the cap are rejected with 503, preventing memory exhaustion via repeated initialize requests.

Assisted-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Sergey Vilgelm <sergey@vilgelm.com>
Replace the single global RwLock<HashMap> with 16 independently locked shards, reducing contention on the session dispatch path under load. Trait surface unchanged.

Assisted-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Sergey Vilgelm <sergey@vilgelm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant