Skip to content

Scrape size on clusters with a very large number of consumer group partitions #38

In progress

Description

@acgtun

Why this matters

Partition-level consumer lag is how operators find a single stuck or slow partition: a consumer that stopped on one partition, a hot key, or a partition that fell behind after a reassignment. Topic-level aggregates hide which partition is behind, and a sum over a large topic can hide the lag of one partition entirely. Clusters that rely on partition-level lag today with kafka_exporter need the same from Sova, at the same scale.

The problem

One of our clusters has about 85K topic partitions in about 120 topics (roughly 700 partitions per topic) and about 600 consumer groups. Many of those groups consume the large topics, so the cluster has about 800K partition-level consumer lag series (group x topic x partition). With kafka_exporter, exporting these from one instance caused scrape timeouts and missing partition lag metrics.

The size of /metrics is driven by the number of lag series, not by the number of topics, partitions or groups alone. A cluster with fewer partitions and fewer groups than the 10K topics / 100K partitions / 50K groups test in #37 can still export far more lag series, when each group consumes topics with hundreds of partitions.

Part of the kafka_exporter problem was fetching offsets inside the scrape, which Sova already avoids. With collection moved out of the scrape path, the scrape itself remains the bottleneck: split across several instances of about 200K series each, the slowest scrapes still take most of the scrape timeout.

Activity

  1. acgtun commented on Dec 1, 2026

    @acgtun
    Author

    Test results for the sharding in #37, on a 12-broker Kafka 4.2.0 cluster (RF 3, 700 partitions per topic). Each consumer group commits offsets on 2 topics (1,400 partitions), lag is 10 on every partition. Prometheus scrapes every 30s with a 25s timeout; Sova runs with a 6 GiB heap and a 30s collect interval. For comparison, a kafka_exporter build with batched ListOffsets and topic sharding ran against the same cluster at the same time.

    Lag series Partitions / groups Sova, 1 instance Sova, 4 shards kafka_exporter, 1 instance kafka_exporter, 4 shards
    840K 84K / 600 scrape 7-10s, cycle 24-29s scrape 1.5-2.5s, cycle 4-10s - -
    1.68M 84K / 1,200 scrape 15-24s, cycle 25-37s scrape 2.5-6s, cycle 4.5-9s OOMKilled at 8 GiB scrape 4-8s, 2.1-2.5 GiB per shard
    2.52M 168K / 1,800 no lag exported: cycles 223-320s, offset lookups for all 168,050 partitions timed out scrape 4-7s, cycle 24-39s - scrape 6-17s, 4.5-6.1 GiB per shard
    • A single Sova instance works up to about 1.7M lag series, with scrapes close to the timeout and cycles past the collect interval. At 2.5M it exports no lag metrics.
    • With 4 shards, the union of the shards covered every lag series exactly once (verified at 840K: 840,000 series, 0 duplicates).
    • At 2.5M lag series, 4 shards keep scrapes short but the cycle reaches the 30s interval, so that size needs more shards or a longer interval.
  2. scholzj commented on Dec 1, 2026

    @scholzj
    Member

    @Frawless FYI ^^^

    @acgtun Thanks

  3. acgtun commented on Dec 1, 2026

    @acgtun
    Author

    Two more runs at 2.52M lag series (168K partitions, 1,800 groups), each with nothing else running against the cluster.

    • One instance, with default.api.timeout.ms=300000, request.timeout.ms=120000 and a 120s collect interval: it completes, but cycles take 121-315s, and /metrics is 526 MB (6.2M samples) and takes 17-31s to scrape.
    • 8 shards, default settings: scrapes take 1.3-3.4s, with 0.48-0.83M samples per shard. Steady cycles take 26-39s, the same as with 4 shards.

    Sharding divides the exported series, so scrape time falls with the shard count. Collection time does not: each shard still looks up latest offsets for every partition its groups consume, including topics owned by other shards. One shard logged 128,100 such lag-only partitions out of 168,050, and with default timeouts that lookup timed out and its cycle took 103-111s.

  4. Frawless commented on Dec 1, 2026

    @Frawless
    Member

    Thanks for the numbers, I will take a closer look on it tomorrow and will get back here.

  5. scholzj commented on Dec 2, 2026

    @scholzj
    Member

    @acgtun So, what do the scrape and cycle values mean? I assume scrape is how long it took Prometheus to scrape it? Or is it scraped by curl or something to eliminate Prometheus? But I have no idea how do you measure cycla / what exactly it means?

  6. Frawless commented on Dec 2, 2026

    @Frawless
    Member

    Cycle should be how long it took to Sova to collect all the data from Kafka (user can configure this interval). Scrape should be time that sova needs for data preparation for prometheus - when Prometheus request lands, it will start compressing the data for Prometheus. At least that's how I understand it.

  7. acgtun commented on Dec 2, 2026

    @acgtun
    Author

    Both are measured by the Prometheus server that scraped the instances during the tests, not by curl.

    • Scrape is Prometheus' own scrape_duration_seconds for the Sova target: the whole HTTP request to /metrics. On the Sova side that is building the metric families from the last collected snapshot, serializing them as text and gzipping them. On the Prometheus side it is transferring and parsing the response. A scrape does not call Kafka. Its time grows with the number of exported series, and splitting the series across shards is what shortens it. Prometheus scraped every 30s with a 25s timeout, so a scrape longer than 25s fails.
    • Cycle is sova_collection_duration_seconds, which Sova exports: the wall-clock time of the last finished collection pass. A pass makes every Admin API call (list and describe topics and groups, fetch committed offsets, list offsets) and then publishes a new snapshot. The gauge is set for failed cycles too, so the 223–320s values in the first table are cycles that failed. Successful and failed cycles are counted with sova_last_successful_collection_timestamp_seconds and sova_collection_failures_total.

    The collect interval is not the cycle time. Sova schedules collection with a fixed delay, so the next cycle starts one interval after the previous one ends. With a 30s interval, a 30s cycle means a new snapshot about every 60s.

    The sharded cycle times in this issue (24–39s with 4 and 8 shards) were measured on the first commit of #37. With the change now pushed to #37, where lag is reported by the topic's shard, the same 2.52M-series cluster gives cycles of 3.0–8.1s with 4 shards and 1.1–2.3s with 8. The broker-side cost of that change is in the PR comments.

  8. Frawless commented on Dec 2, 2026

    @Frawless
    Member

    @acgtun hey, I spent some time with it today and after discussion with @mimaison I created #41 . It significantly improved the performance with single instance without need of the sharding at least for collection. The scrape could be also resolved by pre-rendering (compress data after collection) of the data so in case the data will be too long I would expect that first scrape could fail, but once Sova finishes the first pre-render, it should then work fine as the render will happen only once per collection cycle instead of with every http request.

    Would be possible for you to give it a try on your setup? The binaries are here https://github.com/strimzi/sova/actions/runs/46978825692?pr=41 (see artifacts section). Also check table on the PR with results from perf measurements. It was just with one broker, but even in that I saw significant improvement. In case this will work for you, it will be much simpler solution than sharding implementation.

  9. acgtun commented on Dec 2, 2026

    @acgtun
    Author

    @acgtun hey, I spent some time with it today and after discussion with @mimaison I created #41 . It significantly improved the performance with single instance without need of the sharding at least for collection. The scrape could be also resolved by pre-rendering (compress data after collection) of the data so in case the data will be too long I would expect that first scrape could fail, but once Sova finishes the first pre-render, it should then work fine as the render will happen only once per collection cycle instead of with every http request.

    Would be possible for you to give it a try on your setup? The binaries are here https://github.com/strimzi/sova/actions/runs/46978825692?pr=41 (see artifacts section). Also check table on the PR with results from perf measurements. It was just with one broker, but even in that I saw significant improvement. In case this will work for you, it will be much simpler solution than sharding implementation.

    Thanks @Frawless for the great improvement. yeah, let me try it now.

  10. acgtun commented on Dec 3, 2026

    @acgtun
    Author

    @Frawless @scholzj

    Tested #41 (e19cae7) as a single instance, no sharding, on a test cluster with 12 brokers, 241 topics, 168,050 partitions and 1,800 consumer groups, giving 2.52M lag series. Default admin client settings, 30 s collection interval, Prometheus scraping every 30 s with a 25 s timeout.

    main, 1 instance #41, pool 4 #41, pool 8
    Collection cycle 223–330 s, all cycles failed 21–25 s 5.4–7.8 s
    Successful / failed cycles in 10 min 0 11 / 0 15 / 0
    Lag series exported 0 2,520,000 2,520,000
    Scrape duration 17–31 s with long timeouts 5–8 s 4.8–8.4 s
    Render duration – ~13 s 13–16 s
    Heap used – 2.9 GB 2.6 GB

    Both problems are resolved at this size: collection completes every cycle and every scrape succeeds. With pool 8 the extra broker load was about 0.5 cores across 12 brokers, compared with about 1.1 cores for 8 shards. Served data is up to about 50 s old (interval + cycle + render).

    Rolling restart of all 12 brokers (pool 8, 24 minutes): 41 successful cycles, 0 failed, every scrape succeeded, and partition series were complete throughout. Cycle time rose to 13–15 s once per broker restart. During 4 of the 12 broker restarts, between 36 and 220 groups (2–12% of lag series) were missing from the output for one to three 30 s samples. No warning was logged and the failure counter did not move, so the Admin calls succeeded but returned fewer groups. The likely cause is group coordinators moving between brokers. Alerts based on missing lag series will see these gaps during a roll.

    Doubled groups (3,600 groups, 5.04M lag series, pool 8):

    2.52M lag series 5.04M lag series
    Collection cycle 5.4–7.8 s 8.2–11.4 s
    Successful / failed cycles in 10 min 15 / 0 14 / 0
    Scrape duration 4.8–8.4 s 9.8–15.3 s
    Render duration 13–16 s 23.5–27.8 s
    Served data age, max 58 s 65 s
    Heap used, peak (6 GB max) 2.6 GB 5.5 GB
    Sova CPU ~0.7 cores ~1.4 cores

    Collection still keeps up at 5.04M series, and its cost per series is flat. Everything else that grows with the series count is now close to a limit on a single instance: heap is 5.5 of 6 GB, render takes nearly the full 30 s interval, and scrape duration would reach the 25 s timeout at about 8–9M lag series. Beyond that size the series need to be split across instances.

  11. Frawless commented on Dec 3, 2026

    @Frawless
    Member

    Great, that looks good to me! I am going to submit one more change related to render. It should significantly improve memory usage and whole render duration. I will share the link to artifacts once it will be ready.

  12. Frawless commented on Dec 3, 2026

    @Frawless
    Member

    @acgtun Alright, here it is https://github.com/strimzi/sova/actions/runs/47198976600 , I tried to improve rendering of data to have memory handling better and improve the render speed. If you would be able to try it I would really appreciate it.

  13. acgtun commented on Dec 4, 2026

    @acgtun
    Author

    @acgtun Alright, here it is https://github.com/strimzi/sova/actions/runs/47198976600 , I tried to improve rendering of data to have memory handling better and improve the render speed. If you would be able to try it I would really appreciate it.

    sure. thanks @Frawless, let me try

  14. acgtun commented on Dec 4, 2026

    @acgtun
    Author

    @Frawless Tested the build from run 47198976600 (f0a679f) on the same test cluster: 12 brokers, 168,050 partitions, 3,600 consumer groups, 5,040,000 lag series.

    Both builds ran with the same settings (-Xms6g -Xmx6g, STRIMZI_ADMIN_CLIENT_POOL_SIZE=8, pre-rendering on), one at a time on the same host, for 10+ minutes each:

    previous head (e19cae7) this build (f0a679f)
    sova_render_duration_seconds 25.1 s 4.4 – 5.2 s
    sova_collection_duration_seconds 11.2 s 9.3 – 10.0 s
    Process RSS, steady state 6.70 GB 5.30 GB
    Scrape time (~970 MB uncompressed body) 0.70 s 0.62 – 0.68 s
    kafka_consumergroup_lag series 5,040,000 5,040,000
    sova_collection_failures_total 0 0

    Render is about 5x faster and RSS is about 1.4 GB lower at the same heap size. Scrape time is unchanged, as expected, since both builds serve the pre-rendered body. Collection time is unchanged.

  15. Frawless commented on Dec 5, 2026

    @Frawless
    Member

    Awesome, thank you! So I think we can close #37 and proceed with #41 . Thank you for all your testing. In case you have any additional suggestion let me know.

  16. acgtun commented on Dec 5, 2026

    @acgtun
    Author

    @Frawless Thanks for the quick turnaround on the render changes. Closing #37 in favour of #41.

    A few suggestions from the testing:

    1. Missing groups during a broker roll. In the rolling restart test on e19cae7, 36–220 groups were missing from the output for one to three samples during 4 of the 12 broker restarts. No warning was logged and sova_collection_failures_total did not move, so the gap is invisible from Sova's own metrics. A gauge with the number of groups collected per cycle would make this visible. Keeping a group's last values for one cycle when it disappears would close the gap for alerts that fire on missing lag series.
    2. Sizing guidance. With f0a679f, the heap live set after a collection was about 3.4 GB at 5.04M lag series, roughly 0.7 GB per million series. A short sizing note in the README (heap per million series, and when to raise STRIMZI_ADMIN_CLIENT_POOL_SIZE) would help with large clusters. In the tests, a pool of 4 gave 21–25 s cycles and a pool of 8 gave 5–8 s at 2.52M series.
    3. Very large clusters. Render and scrape are no longer the bottleneck, so heap is now the limit on a single instance. Splitting topics and groups across instances is only needed well beyond 5M series, so it can wait until someone hits that size.
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions