Skip to content

A scrape counts the resources where they already are - #505

Open
bjmeetsfo wants to merge 1 commit into
mainfrom
oss/a-scrape-counts-where-the-state-is
Open

A scrape counts the resources where they already are#505
bjmeetsfo wants to merge 1 commit into
mainfrom
oss/a-scrape-counts-where-the-state-is

Conversation

@bjmeetsfo

Copy link
Copy Markdown
Collaborator

Every Prometheus scrape of the metaserver listed each server, each proxy,
each namespace, each table and each proxy group -- five calls, five times
taking the lock, five copies of a collection -- and then used the lengths
and the states and threw the copies away.

Listing a server copies it whole, and a server carries its shard-load list
and its shard-state list: three strings for every shard it holds. A cluster
of thirty-two datanodes holding a thousand shards each had ninety-six
thousand strings copied to answer how many servers are frozen, on every
scrape, on an interval, forever.

The totals were already gathered where the state is held -- MetaStats
carries them. It now carries the per-state breakdown too, counted in the
same pass, and the per-server and per-proxy numbers the scrape reports come
from a row that has those numbers and nothing else.

servers x shards each     before      after
          8 x    250      372 us    19.2 us
         16 x    500    2 360 us    29.9 us
         32 x  1 000    8 559 us    44.6 us

A hundred and ninety times faster at the largest, measured before and after
back to back. It also stops growing with the shards: sixteen times the
shard states cost 2.3 times as much rather than 23 times.

A test registers a server in each state and checks the counts read from the
stats are the counts listing them would have produced.

@bjmeetsfo
bjmeetsfo requested a review from superhaiou as a code owner August 31, 2026 04:54
Every Prometheus scrape of the metaserver listed each server, each proxy,
each namespace, each table and each proxy group -- five calls, five times
taking the lock, five copies of a collection -- and then used the lengths
and the states and threw the copies away.

Listing a server copies it whole, and a server carries its shard-load list
and its shard-state list: three strings for every shard it holds. A cluster
of thirty-two datanodes holding a thousand shards each had ninety-six
thousand strings copied to answer how many servers are frozen, on every
scrape, on an interval, forever.

The totals were already gathered where the state is held -- MetaStats
carries them. It now carries the per-state breakdown too, counted in the
same pass, and the per-server and per-proxy numbers the scrape reports come
from a row that has those numbers and nothing else.

    servers x shards each     before      after
              8 x    250      372 us    19.2 us
             16 x    500    2 360 us    29.9 us
             32 x  1 000    8 559 us    44.6 us

A hundred and ninety times faster at the largest, measured before and after
back to back. It also stops growing with the shards: sixteen times the
shard states cost 2.3 times as much rather than 23 times.

A test registers a server in each state and checks the counts read from the
stats are the counts listing them would have produced.
@bjmeetsfo
bjmeetsfo force-pushed the oss/a-scrape-counts-where-the-state-is branch from 59b5a9c to 089f29a Compare August 31, 2026 08:46
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.

2 participants