Skip to content

fix(server): honor HYPERGLASS_WORKERS for web worker count - #381

Open
WilhelmZA wants to merge 1 commit into
thatmattlove:mainfrom
WilhelmZA:pr/configurable-workers
Open

fix(server): honor HYPERGLASS_WORKERS for web worker count#381
WilhelmZA wants to merge 1 commit into
thatmattlove:mainfrom
WilhelmZA:pr/configurable-workers

Conversation

@WilhelmZA

Copy link
Copy Markdown

Problem

HyperglassSettings.workers is a computed property hardcoded to cpu_count(2)
(2x logical cores) whenever debug is off, and hyperglass/main.py duplicates
that same inference inline. There is no settings field backing it, so the
HYPERGLASS_WORKERS environment variable is silently ignored.

On a 24-core host this starts 48 uvicorn workers regardless of intent — each
a full process holding the app plus its own Redis connections — with no
supported way to cap it. For a looking glass that is far more than needed.

Fix

  • Add a real workers settings field (HYPERGLASS_WORKERS), Optional[int],
    default None.
  • Replace the unused workers property with worker_count, which honors the
    field (clamped to >= 1) and otherwise keeps the previous behavior: 1 in
    debug mode, else 2x CPU cores.
  • run() now uses Settings.worker_count instead of duplicating the inference.
HYPERGLASS_WORKERS debug workers
unset false 2x cores (unchanged default)
unset true 1 (unchanged)
4 either 4
0 either 1 (clamped)

Notes

  • Self-contained: touches only models/system.py and main.py, independent of
    any other in-flight work, and applies cleanly to the current main.
  • Backward compatible — the default is unchanged when HYPERGLASS_WORKERS is
    unset.
  • Adds unit tests for worker_count.

The web-worker count was hardcoded to 2x CPU cores when debug was off (via an
unused `workers` property and duplicate inline logic in run()), so a 24-core
host span 48 uvicorn workers and the documented HYPERGLASS_WORKERS env var was
silently ignored.

Add a real `workers` settings field (HYPERGLASS_WORKERS) and a `worker_count`
property that honors it (clamped to >= 1), falling back to 1 in debug mode or
2x CPU cores otherwise. run() now uses Settings.worker_count.
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