fix(server): add --workers flag to prevent single blocking request stalling HTTP server#465
Closed
r266-tech wants to merge 1 commit intovolcengine:mainfrom
Closed
fix(server): add --workers flag to prevent single blocking request stalling HTTP server#465r266-tech wants to merge 1 commit intovolcengine:mainfrom
r266-tech wants to merge 1 commit intovolcengine:mainfrom
Conversation
…alling HTTP server Fixes #464 ## Problem OpenViking started uvicorn with a single worker (no `workers=` argument), meaning one slow or blocking request could stall the entire server process, including lightweight endpoints such as /health. ## Solution Add a `workers` configuration knob with three touch-points: 1. `ServerConfig.workers` (default 1) - new field in the server dataclass, loaded from ov.conf under `server.workers`. 2. `--workers N` CLI flag - lets operators set the worker count at startup without editing ov.conf. 3. `validate_server_config` - rejects workers < 1 with a clear error message and a non-zero exit code. ### Multi-worker launch strategy When workers > 1, the app is passed to uvicorn.run() as an import string with factory=True so each forked worker process independently imports and initialises its own OpenVikingService instance. The config file path is propagated via the OPENVIKING_CONFIG_FILE environment variable that is already set earlier in main(). Single-worker mode (workers=1, the default) is fully backward- compatible and continues to support the vikingbot gateway subprocess. ### Limitations / known constraints * --with-bot is not supported together with --workers > 1; a warning is emitted and the bot proxy is skipped. Bot mode requires a separate single-worker server instance. * Multiple workers each hold their own in-memory state. If OpenViking is configured with a local SQLite backend, concurrent writes from multiple workers may cause contention; using a networked storage backend is recommended for production multi-worker deployments. ## Tests Added tests/server/test_server_workers_config.py covering: - ServerConfig defaults to workers=1 - Custom workers value is stored correctly - validate_server_config rejects workers=0 and workers=-1 - validate_server_config accepts workers=1 and workers=4 - load_server_config reads workers from the config file - load_server_config defaults workers to 1 when absent
Collaborator
|
你测过能 work 吗?我也 vibe 过类似的版本,但有些问题 |
Contributor
Author
|
Superseded by #470 with cleaner implementation approach. |
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
Fixes #464
OpenViking started uvicorn with no
workersargument (defaulting to 1), which means one slow or blocking request can stall the entire HTTP server process — including lightweight probes like/health.This PR adds a
workersconfiguration knob so operators can run multiple uvicorn worker processes and prevent this availability issue.Changes
openviking/server/config.pyworkers: int = 1field toServerConfigserver.workersfromov.confvalidate_server_config: rejectworkers < 1with a clear error andsys.exit(1)openviking/server/bootstrap.py--workers NCLI argumentworkers == 1(default): existing behaviour unchanged, app object passed directly touvicorn.run()workers > 1: useuvicorn.run('openviking.server.app:create_app', factory=True, workers=N)so each worker process independently imports and initialises its ownOpenVikingService. The config file path is propagated via theOPENVIKING_CONFIG_FILEenv var already set inmain()tests/server/test_server_workers_config.py(new)ServerConfigdefaults toworkers=1validate_server_configrejectsworkers=0andworkers=-1validate_server_configacceptsworkers=1andworkers=4load_server_configreadsworkersfrom config fileload_server_configdefaultsworkersto1when absentUsage
Limitations
--with-botis not supported with--workers > 1(warning emitted, bot proxy disabled). Bot mode requires a separate single-worker instance.Backward Compatibility
Default is
workers=1, so all existing deployments are unaffected.