-
Notifications
You must be signed in to change notification settings - Fork 129
Open
Description
Describe the bug
During load testing in #837, profiling shows heavy lock contention in EpisodicMemoryManager and low requests-per-second in locust, even with a low number of users. The problem is worse as we add more users and load.
Steps to reproduce
Use the locustfile.py and profile_memmachine.sh from #837 to generate the load and profile the FastAPI processes running inside the memmachine-app Docker container.
Expected behavior
- Remove serialization locks in high contention code paths.
- Expect higher Requests per Second per FastAPI worker with Locust.
Environment
- OS: Ubuntu Linux 25.04
- MemMachine: v0.2.2
- Locust load generator
Additional context
The open_or_create_episodic_memory method currently holds a global lock while performing database I/O to fetch session info. This serializes all requests to that worker.
Suggested Solution: Use a double-checked locking pattern or a per-session lock to allow concurrent I/O for different sessions.