Skip to content

bug: potential rotuer memory leak #707

Open

Description

@can-sun

Describe the bug

I found that router image memory utilization will steadily go up by running long stability tests. The test is performed using RoundRobin strategy thus no HashTrie and HashTrie nodes are created.

Image

To Reproduce

  • Deploy the router image on EKS connecting to a bunch of existing model servers, use the round robin routing strategy
  • Enable the EKS container insights thus we can check the pod memory utilization
  • Start the long-running benchmark test against the router image endpoint. Currently our test traffic is very predictable and steady. E.g 100 concurrent request. And every user will ask 5 questions. The input context is selected from a fixed pool.
  • Check the memory usage of the route pod. You will identify the steady trend of memory usage going up

Expected behavior

The memory usage should go up and down. The usage should be around a baseline per testing.

Additional context

No response

Activity

  1. added
    bug
    on Sep 19, 2025
  2. babu97 commented on Oct 23, 2026

    @babu97

    I have also experience this issue in my production environment
    The production-stack router (vllm-router) shows a slow but steady memory leak: RSS grows roughly linearly over time and never plateaus, independent of request volume. Two independent router replicas serving the same traffic grow at an identical rate, which points to the router process itself rather than the environment.

    Growth is slow (~12 MiB/day) so it isn't urgent, but with no memory limit it continues unbounded until the pod is restarted, and over weeks it becomes significant.

    Environment

    Router: vLLM production-stack router (vllm-router), running in Kubernetes
    Python 3.12, aiohttp-based, served via uvicorn/FastAPI
    --routing-logic roundrobin
    --engine-stats-interval 15
    --request-stats-window 60
    2 router replicas, 2 backend vLLM pods

    Image
  3. babu97 commented on Oct 29, 2026

    @babu97

    Profiled it with memray for over ~3 days and the results narrow down the cause

    Setup (reproducible)

    • Image: lmcache/lmstack-router@sha256:7a23717da4742ca327f65d5621a6bb3212c7ee69d2feea780d7a1ae7eaec7717
    • Args: --routing-logic roundrobin --engine-stats-interval 15 --request-stats-window 60
    • Backends: 4× Qwen3-4B, K8s pod-ip service discovery
    • Container memory limit 1000Mi in normal operation (removed during profiling so RSS
      wasn't OOM-killed mid-capture)
    • RSS climbs ~[FILL: X] MiB/day, linear, identical on both replicas, no restart.

    Method

    memray attach to the router process (PID 1) for ~3 days under normal traffic, then
    detached and analysed off-pod.

    Key finding

    Total memory allocated: 130.8 GB (cumulative over 3 days)
    Peak memory usage: 56.7 MB (flat for the whole capture)
    Total allocations: 57.3 M

    Peak live memory stayed at ~57 MB the entire time. A genuine object leak would
    show live memory tracking the RSS climb — it doesn't. The 130 GB is churn (allocated
    then freed), not retention.

    Where the churn comes from

    Top allocators by cumulative size:

    • json.raw_decode + json.loads → ~76 GB
    • prometheus_client text parsing (text_string_to_metric_families) → ~13 GB
    • starlette route matching + prometheus metric-object creation → ~7 GB
    • By module: vllm_router 79.8 GB, prometheus_client 21.9 GB

    These sit on the engine-stats scrape path
    (_scrape_worker → _scrape_one_endpoint → from_vllm_scrape → text_string_to_metric_families)
    and the /metrics exposition (generate_latest → sample_line), plus per-request
    JSON handling on the chat route.

    Why RSS still grows

    memray flamegraph --leaks flagged it directly:

    generated with the pymalloc allocator active... the allocator retains memory in
    memory pools even after the objects are deallocated, and Memray won't be able to
    distinguish memory set aside for reuse from leaked memory.

    So the memory is freed at the app level but retained by the allocators (pymalloc
    pools + glibc per-thread arenas) under very high scrape/parse churn — classic
    fragmentation signature, not a reference leak.

    Mitigation (testing)

    Capping glibc arenas on the router:

    env:
      - name: MALLOC_ARENA_MAX
        value: "2"
      - name: MALLOC_TRIM_THRESHOLD_
        value: "131072"

    Possible upstream improvements

    • Document MALLOC_ARENA_MAX guidance for the router (or ship jemalloc in the image).
    • The dominant allocator is metrics scraping, so --engine-stats-interval and the
      prometheus text-parse cost are the levers for reducing churn.
    Image Image Image Image Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions