Repository navigation
Closed
Labels
area: distributedDistributed coordination and consensuseffort: smallSmall effort - 2-4 hourspriority: highImportant issue that should be addressed soontype: technical-debtCode refactoring, cleanup, or architecture improvements
Description
Context
NodeInfo in cluster.go has CPUUsage, MemoryUsage, DiskUsage, and CacheHitRate fields that are never populated. The StrategyLeastLoad load balancer therefore always sees zero load on all nodes and makes random selections rather than informed ones. Real stats are needed for cache-warming decisions in v0.12.0.
What to implement
Add to internal/distributed/gossip.go:
MessageTypeNodeStats MessageType = "node_stats"
type NodeStatsMessage struct {
NodeID string `json:"node_id"`
CPUUsage float64 `json:"cpu_usage"` // 0.0–1.0 from runtime
MemoryUsage float64 `json:"memory_usage"` // HeapInuse / HeapSys
CacheHitRate float64 `json:"cache_hit_rate"` // from cache.Stats().HitRate
}In the gossip heartbeat loop (sendHeartbeats or equivalent), build a NodeStatsMessage for the local node:
CPUUsage: useruntime.ReadMemStatsas a proxy (HeapInuse/HeapSys) — a real CPU sample viaosis optionalMemoryUsage:ms.HeapInuse / ms.HeapSysCacheHitRate: callgp.cluster.cache.Stats().HitRateif cache is non-nil, else 0
Broadcast alongside the heartbeat. Handle MessageTypeNodeStats in handleIncomingMessage by calling gp.cluster.UpdateNodeInfo with the received values.
Acceptance criteria
NodeStatsMessagestruct andMessageTypeNodeStatsconstant defined- Gossip heartbeat sends stats for the local node every heartbeat period
- Receiving node updates
NodeInfo.CacheHitRate,MemoryUsageviaUpdateNodeInfo - Integration test: start two nodes, wait 2× heartbeat interval, verify node B's view of node A has
CacheHitRate >= 0andMemoryUsage > 0 go test -race ./internal/distributed/...passes
Sequencing
Independent — can land any time in v0.11.0.
Metadata
Metadata
Assignees
Labels
area: distributedDistributed coordination and consensuseffort: smallSmall effort - 2-4 hourspriority: highImportant issue that should be addressed soontype: technical-debtCode refactoring, cleanup, or architecture improvements
Activity
scttfrdmn commentedon Aug 3, 2026
Verified this issue's premises before implementing. Two of them do not hold, and there is a
prerequisite defect the plan does not mention — implementing as written would produce a feature that
appears to work in a two-node test and reports a frozen value forever in production.
The transport already exists
performGossip(gossip.go:756-773) already sendsgp.localNode— the wholeNodeInfo, includingCPUUsage,MemoryUsage,DiskUsage,CacheSize,CacheHitRate, andOperations— inside everyAliveMessage, andhandleAliveMessage(gossip.go:531-533) already applies it viaUpdateNodeInfo, which copies all six fields (cluster.go:575-582).So a new
MessageTypeNodeStatsandNodeStatsMessagewould be a second channel carrying a subset ofwhat the first one already carries, and a second thing to remember to authenticate, count, and
version. What is actually missing is narrower: nothing ever writes those fields on
gp.localNode.It is built once at
gossip.go:194-201with the six stats fields at their zero values and neverupdated, so the transport faithfully delivers zeros.
Prerequisite: stats would freeze at the first value received
handleAliveMessageonly applies an update whenaliveMsg.Incarnation > gossipNode.Incarnation(
gossip.go:522). Nothing in the package ever increments an incarnation — the only two writes to thefield (
gossip.go:523,gossip.go:672) both copy a received value, andgetCurrentIncarnationreturns the stored
1. So after a node is first discovered, every later alive message from it isdropped, and its stats hold whatever they were at discovery.
Proven by execution rather than read off the source, with a throwaway probe driving
handleIncomingMessagetwice with sealed alive messages carrying different values:This matters for the acceptance criteria as written. "Start two nodes, wait 2× heartbeat interval,
verify node B's view of node A has
MemoryUsage > 0" passes on the broken code: the first alivemessage is applied, so if the local node populates its stats before gossip starts, the first value
lands and the assertion is satisfied. The test would then be green while the metric is frozen for the
lifetime of the process — and a stale cache hit rate is worse than an absent one, because a
cache-warming decision made on it looks informed.
The test has to assert that a changed value propagates, not that a non-zero one arrived.
Two premises that are wrong
StrategyLeastLoaddoes not read these fields.selectLeastLoad(coordinator.go:906-925)sorts on
lb.stats.NodeLoad, which is populated —coordinator.go:297increments it per routedoperation. So least-load is not making random selections for want of these fields; it is balancing on
locally-observed request counts. That may be the wrong signal, but it is a different issue from this
one, and fixing this one will not change its behaviour.
What actually reads the fields is
calculateStats(cluster.go:544-562), which averagesCacheHitRateacross alive nodes intoClusterStats.CacheHitRate— reported throughGetStatsandcurrently always 0.
CPUUsagecannot beHeapInuse/HeapSys. That ratio is memory, which is what the issue alsoassigns to
MemoryUsage— so the two fields would carry the same number under different names, and aload-balancing decision reading
CPUUsagewould be reading heap fragmentation. Better to populateMemoryUsagefromruntime.ReadMemStatsand leaveCPUUsageat zero, documented asunpopulated, than to fill it with a plausible-looking number from an unrelated quantity. A field that
is obviously zero prompts someone to implement it; a field carrying the wrong measurement does not.
Adjacent defect found in the same function
calculateStatsaccumulatestotalCacheSizeacross alive nodes and then discards it —_ = totalCacheSizeatcluster.go:562.ClusterStatshas no cache-size field to put it in. So theloop does the work and drops the result. Worth fixing in the same change, since it is three lines from
the code that has to be touched anyway: either add the field or delete the accumulation.
Revised scope
after the first are not dropped. This is the prerequisite; without it nothing else in this issue
has an observable effect after startup.
gp.localNode's stats before broadcasting, fromruntime.ReadMemStatsand, when a cacheis set via
SetCache,cache.Stats(). No new message type — the alive message already carriesthem.
totalCacheSize.CPUUsage,DiskUsage, andNetworkBandwidthat zero with a comment saying so and why,rather than filling them with proxies from unrelated quantities.
bug.
fix: let a node contradict a false report of its own death (#273)
feat: measure the node statistics gossip has always carried
feat: measure the node statistics gossip has always carried (#274)