Skip to content

New warm-first Load Balancer #166

Open

Description

@thushan

Add a backend-agnostic warm-first load balancer that prefesrs endpoints where the requested model is already resident in memory, avoiding cold-load latency (10-30s weight load + possible LRU eviction) on multi-model backends.

This generalises the backend-specific approach proposed in #152 into a strategy that works across any backend able to report model residency.

Backend Source Notes
oMLX GET /v1/models/status (loaded: bool) multi-model
Ollama GET /api/ps multi-model
LM Studio JIT model state hot/cold
vLLM / SGLang / llama.cpp single-model always warm

The warm-first balance would wrap something like sticky( warmFirst( baseBalancer ) ) and something high-level like this:

Select(candidates, requestedModel):
      warm = [e for e in candidates if residency.IsResident(e, requestedModel) == (true, true)]
      if warm is non-empty:
          return base.Select(warm, requestedModel)   # delegate within warm set
      return base.Select(candidates, requestedModel)  # nobody warm → normal behaviour

Activity

  1. self-assigned this
    on Jun 7, 2026
  2. added
    enhancement
    routing
    on Jun 7, 2026
  3. bongiozzo commented on Jun 7, 2026

    @bongiozzo

    4 requests in one session of opencode to freshly restarted thunder-forge (olla/omlx) cluster

    {"timestamp":"2026-06-07T23:07:12.999977+04:00","request_id":"533e256e5aa2466bacc2fb32745b32d5","client_id":"admin","path":"/v1/chat/completions","model":"coder","status_code":200,"latency_ms":12655,"olla_endpoint":"msm3-omlx-live","node_name":"msm3"}
    {"timestamp":"2026-06-07T23:07:19.435593+04:00","request_id":"3bfd357f85384e9abc91a1774e4546ac","client_id":"admin","path":"/v1/chat/completions","model":"coder","status_code":200,"latency_ms":19039,"olla_endpoint":"msm2-omlx-live","node_name":"msm2"}
    {"timestamp":"2026-06-07T23:08:41.699846+04:00","request_id":"1ce80d2586ca467dab7fe7fbac4e98a2","client_id":"admin","path":"/v1/chat/completions","model":"coder","status_code":200,"latency_ms":15945,"olla_endpoint":"msm1-omlx-live","node_name":"msm1"}
    {"timestamp":"2026-06-07T23:09:05.506757+04:00","request_id":"361501d1327b4d59858502433fc305b0","client_id":"admin","path":"/v1/chat/completions","model":"coder","status_code":200,"latency_ms":3758,"olla_endpoint":"msm1-omlx-live","node_name":"msm1"}
    {"timestamp":"2026-06-07T23:09:24.407820+04:00","request_id":"ee0e5bd5e62d49d594c89846189cf2f1","client_id":"admin","path":"/v1/chat/completions","model":"coder","status_code":200,"latency_ms":1479,"olla_endpoint":"msm1-omlx-live","node_name":"msm1"}
    

    first request touched msm3 and msm2 nodes simultaneously with significant delay for loading.
    second, third and forth gone to msm1 and were fast

    Generated Olla config:

    # AUTO-GENERATED by thunder-forge generate-olla-config
    # from tfconfig.yaml
    # Do not edit manually — edit tfconfig.yaml instead.
    
    server:
      host: 127.0.0.1
      port: 40115
      read_timeout: 20s
      write_timeout: 0s
      shutdown_timeout: 10s
      request_logging: true
    proxy:
      engine: olla
      profile: auto
      load_balancer: least-connections
      connection_timeout: 5s
      response_timeout: 120s
      read_timeout: 120s
      sticky_sessions:
        enabled: true
        idle_ttl_seconds: 600
        max_sessions: 10000
        key_sources:
        - session_header
        - prefix_hash
        - auth_header
        prefix_hash_bytes: 512
      retry:
        enabled: true
        on_connection_failure: true
        max_attempts: 0
    discovery:
      type: static
      refresh_interval: 30s
      health_check:
        initial_delay: 1s
      static:
        endpoints:
        - url: http://msm1-wifi.lan:8018
          name: msm1-omlx-live
          type: omlx
          priority: 100
          model_url: /v1/models
          health_check_url: /health
          check_interval: 3s
          check_timeout: 2s
          model_filter:
            include:
            - gpt-oss-20b-mxfp4-bf16
            - Qwen3-Coder-Next-mxfp8
        - url: http://msm2-wifi.lan:8018
          name: msm2-omlx-live
          type: omlx
          priority: 100
          model_url: /v1/models
          health_check_url: /health
          check_interval: 3s
          check_timeout: 2s
          model_filter:
            include:
            - gpt-oss-20b-mxfp4-bf16
            - Qwen3-Coder-Next-mxfp8
        - url: http://msm3-wifi.lan:8018
          name: msm3-omlx-live
          type: omlx
          priority: 100
          model_url: /v1/models
          health_check_url: /health
          check_interval: 3s
          check_timeout: 2s
          model_filter:
            include:
            - gpt-oss-20b-mxfp4-bf16
            - Qwen3-Coder-Next-4bit
            - Qwen3.6-35B-A3B-4bit
            - Qwen3.6-35B-A3B-mxfp8
        - url: http://msm4-wifi.lan:8018
          name: msm4-omlx-live
          type: omlx
          priority: 100
          model_url: /v1/models
          health_check_url: /health
          check_interval: 3s
          check_timeout: 2s
          model_filter:
            include:
            - gpt-oss-20b-mxfp4-bf16
            - Qwen3-Coder-Next-4bit
            - Qwen3.6-35B-A3B-4bit
            - Qwen3.6-35B-A3B-mxfp8
      model_discovery:
        enabled: true
        interval: 5m
        timeout: 10s
        concurrent_workers: 2
        retry_attempts: 1
        retry_backoff: 1s
    model_registry:
      type: memory
      enable_unifier: true
      routing_strategy:
        type: strict
        options:
          fallback_behavior: compatible_only
          discovery_timeout: 2s
          discovery_refresh_on_miss: false
    logging:
      level: info
      format: json
      output: /mnt/samsung/thunder-forge/logs/olla.log
    model_aliases:
      memory:
      - gpt-oss-20b-mxfp4-bf16
      coder-better:
      - Qwen3-Coder-Next-mxfp8
      coder:
      - Qwen3-Coder-Next-4bit
      agent:
      - Qwen3.6-35B-A3B-4bit
      agent-better:
      - Qwen3.6-35B-A3B-mxfp8
    

    Expected behavior with balancer - all requests go to one node.

    Right?

  4. ccsmart commented on Jun 16, 2026

    @ccsmart

    I think the problem will be on fresh start.
    eg a pair of strong and a pair of weaker servers, but all are strong enough for all models, just slower on the weaker ones. weaker ones are supposed to be fallback for heavy model request overload on the stronger servers. eg 2 heavy models for chat, 1 for embedding, 1 for rerank. you'd want embedding and rerank on the lighter ones, one of the chat models on the stronger ones each.
    but initial requests after starting up the system may distribute and stick the wrong way round.
    i think automations here will quickly get complex and always have different opinions on what is right,
    imo low hanging fruit, manual priorities as in #84

  5. sg-shag commented on Jun 17, 2026

    @sg-shag

    Expected behavior with balancer - all requests go to one node.

    Right?

    Not exactly. The practical expectation for us is narrower:

    • requests with the same sticky key should keep going to the same node while that sticky mapping is alive
    • not all requests globally going to one node

    What ended up working for us in Thunder Forge / oMLX was a very simple setup:

    • auth is implemented on the frontend / edge
    • the edge forwards Authorization to Olla
    • if the client already has a sticky session header, the edge forwards that too
    • Olla sticky sessions use:
      • session_header first
      • auth_header second

    That gives us a KISS split of responsibilities:

    • X-Olla-Session-ID for explicit conversation/session stickiness and KV-cache locality
    • Authorization as the fallback sticky key for clients that do not send a session header

    One important frontend detail: the edge must not invent a new session id on every request. We had that bug for a while, and it prevented auth_header fallback from ever being used. Once we changed the edge to only forward X-Olla-Session-ID when the client actually sent one, this started behaving correctly.

    Current generated Olla config excerpt:

    proxy:
      engine: olla
      profile: auto
      load_balancer: least-connections
      connection_timeout: 5s
      response_timeout: 120s
      read_timeout: 120s
      sticky_sessions:
        enabled: true
        idle_ttl_seconds: 600
        max_sessions: 10000
        key_sources:
        - session_header
        - auth_header
        prefix_hash_bytes: 512

    So for now, for our use case, this has been enough:

    • Sticky-Session for KV-cache
    • Auth for user-level affinity fallback

    That is simple, understandable, and good enough for balancing today, without adding more routing policy yet.

  6. aggieturing-code commented on Sep 4, 2026

    @aggieturing-code

    Warm-first / KV-resident-aware balancing is the right instinct. GateLLM pairs weighted load balancing with sticky session affinity so repeated turns pin to the same upstream and keep prompt-cache locality, plus health checks to skip cold or failed endpoints. Same idea, applied across any backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementrouting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions