Skip to content

RabbitMQ consumer endpoint cache is keyed by routing key and thrashes on high-cardinality keys #643

Closed

Description

@thomhurst

Summary

For each received message the RabbitMQ consumer looks up tracing state in a cache keyed by exchange and routing key, capped at 256 entries. A queue bound with a wildcard that receives routing keys containing identifiers (for example order.<id>) misses on almost every message. Each miss takes a lock, concatenates strings, allocates tracing objects and evicts an entry. It also puts the full routing key into the span destination name, which makes span names high-cardinality.

Evidence

src/Relayer.RabbitMQ/RabbitMqEndpointCache.cs:25-41: ConcurrentDictionary keyed by (exchange, key), Destination = exchange + ":" + key + ":" + queue, FIFO eviction at capacity.

Proposal

Key the per-consumer tracing state by queue (computed once) and add the routing key as a span attribute only when the span is recorded.

Found by reading the code at 02fe06f; not reproduced at runtime unless stated.

Acceptance criteria

  • Remove routing-key-dependent tracing composition/eviction from the successful receive path; use bounded or per-consumer state rather than retaining arbitrary routing keys.
  • Preserve convention-defined process/settle names and attributes and assess sampler inputs at span creation; the current site promises actual destination/routing metadata to samplers, so update that documented contract explicitly if changed.
  • Broker-backed tests exercise many distinct routing keys, process/settle telemetry and tracing disabled; extend RabbitMqReceiveBenchmarks with high-cardinality keys and MemoryDiagnoser against equivalent native work.
  • Update RabbitMQ telemetry documentation. No throughput/latency/CPU/allocation trade-off is preapproved.

Activity

  1. added
    bug
    area: transport
    area: performance
    P2
    on Nov 13, 2026
  2. thomhurst commented on Nov 13, 2026

    @thomhurst
    OwnerAuthor

    Audited origin/main at 3dea7d4: RabbitMqEndpointCache still caches (exchange, routing key) with cold composition and eviction. Added high-cardinality benchmark/test criteria and called out the existing sampler-input contract in website/docs/transports/rabbitmq.md; changing it must be explicit rather than silently losing metadata.

  3. added
    in-progress
    on Nov 13, 2026
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

    P2area: performancearea: transportbugin-progress

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions