Repository navigation
feat: support configurable MEMMACHINE_WORKERS and fix circular import - #903
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds configurable worker pool support to MemMachine's FastAPI server to improve performance and scalability. The number of workers is controlled via the MEMMACHINE_WORKERS environment variable, defaulting to 1 to maintain backward compatibility.
- Replaces
uvicorn.Serverwithuvicorn.runto enable multi-process worker support - Adds
MEMMACHINE_WORKERSenvironment variable configuration with validation - Fixes a circular import race condition by importing
memmachine.common.apiearly in__init__.py
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/memmachine/server/app.py | Implements configurable worker pool with environment variable parsing and validation; converts async start() to synchronous start_http() using uvicorn.run |
| src/memmachine/init.py | Adds early import of memmachine.common.api to prevent race condition in multi-worker scenarios |
| sample_configs/env.dockercompose | Adds MEMMACHINE_WORKERS=1 configuration example |
| docker-compose.yml | Passes MEMMACHINE_WORKERS environment variable to the app container with default value of 1 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Steve Scargall <[email protected]>
jealous
approved these changes
Jan 6, 2026
10 of 14 tasks
o-love
pushed a commit
that referenced
this pull request
Jan 23, 2026
Signed-off-by: Steve Scargall <[email protected]>
SarahScargall
pushed a commit
to SarahScargall/MemMachine
that referenced
this pull request
Jan 29, 2026
Signed-off-by: Steve Scargall <[email protected]>
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.
Purpose of the change
This is the first phase of improving MemMachine's overall performance, specifically by increasing the number of users and requests per second (RPS).
Description
By adding a worker pool to FastAPI, we allow users to configure the number of FastAPI workers to handle requests and connections. We default to 1, as we had before. The number of workers is determined by
MEMMACHINE_WORKERSenvironment variable in.env.Users are encouraged to tune the number of workers based on the system resources (vCPU and memory capacity) and the anticipated user load.
Note 1: We need to use
uvicorn.runinstead ofuvicorn.Server, as the latter doesn't support forking new processes, whereas' uvicorn.run' does.Note 2: When using this new
uvicorn.runand forking approach, it highlighted a race condition wherememmachine.commonwasn't imported early enough, so this was added to__init__.pyto resolve this.Fixes/Closes
Fixes #902
Relates to #837
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
Test Results: [Attach logs, screenshots, or relevant output]
Default MEMMACHINE_WORKERS=1
This doesn't change how MemMachine works in existing versions up to v0.2.2.
By default,
docker topshows the primary process (1 worker).The logs now report the number of worker(s):
Default MEMMACHINE_WORKERS=5
When we set the number of workers to 5, we see 5 spawned processes running inside the Docker container.
Checklist
Maintainer Checklist
Screenshots/Gifs
See outputs above from the logs and terminal.
Further comments
While this PR allows users to create a FastAPI worker pool, there are two things to note: