Skip to content

feat: env vars to control model inactivity timeout (QMD_MODEL_KEEP_ALIVE, QMD_MODEL_TTL)#436

Open
DmitryPogodaev wants to merge 1 commit intotobi:mainfrom
DmitryPogodaev:feat/env-model-keep-alive
Open

feat: env vars to control model inactivity timeout (QMD_MODEL_KEEP_ALIVE, QMD_MODEL_TTL)#436
DmitryPogodaev wants to merge 1 commit intotobi:mainfrom
DmitryPogodaev:feat/env-model-keep-alive

Conversation

@DmitryPogodaev
Copy link
Copy Markdown

Problem

In MCP daemon mode on CPU-only servers, the 5-minute inactivity timer disposes model contexts. Recreating contexts takes 500-750ms, which can exceed tight RAG timeouts (1-2s) when combined with session init overhead.

There is currently no way to control this behavior without patching dist/index.js.

Solution

Two environment variables:

  • QMD_MODEL_KEEP_ALIVE=1 — disables the inactivity timer entirely. Models and contexts stay in RAM for the lifetime of the process. Ideal for always-on MCP servers.
  • QMD_MODEL_TTL=<seconds> — overrides the default 300s (5 min) inactivity timeout. Allows tuning without disabling entirely.

Default behavior is unchanged.

Usage

# systemd service
[Service]
Environment=QMD_MODEL_KEEP_ALIVE=1
ExecStart=/path/to/qmd mcp --http

# or just increase timeout to 30 min
[Service]
Environment=QMD_MODEL_TTL=1800
ExecStart=/path/to/qmd mcp --http

Impact

Scenario Without QMD_MODEL_KEEP_ALIVE=1
After 6 min idle 750ms (context recreation) 58ms (instant)
RAM usage ~300MB freed after idle ~300MB permanent

Tested on AMD EPYC 8-core (no GPU), QMD 2.0.1.

Add two environment variables to control LLM model lifecycle:

- QMD_MODEL_KEEP_ALIVE=1 — disable inactivity timer entirely, keeping
  models and contexts in RAM indefinitely. Useful for MCP daemon mode
  on servers where cold-start latency (30-60s on CPU) is unacceptable.

- QMD_MODEL_TTL=<seconds> — override the default 5-minute inactivity
  timeout. Set higher to reduce cold starts, lower to save memory.

Default behavior is unchanged (5 min timeout, models disposed on idle).
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