Repository navigation
Conversation
…pa-clawbot#2221) getNeighborGraph rebuilt Server.neighborGraph on the request goroutine once it passed its 5 min TTL, holding neighborMu for the whole build (~11 s on a production store). The 5 min recomputer went through the same staleness check, so a tick that landed just before the TTL skipped the rebuild and left it to the next request: /api/nodes/{pubkey}/neighbors ran at p95 10.4 s. The request path now serves the current graph and builds only when there is none yet. Every recompute tick rebuilds unconditionally, outside neighborMu, and swaps the pointer. neighborBuildMu keeps a startup request and the first tick from building twice. Without a store the current graph is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Measured after deploying this branch to staging, with production on current master as the control. Method:
The three slow production requests (15:45:27, 15:50:45, 15:56:03 local) are 5 min 18 s apart, which is one TTL plus one build. Caveat: staging holds a shorter packet window, so its background build takes 1.03 s, against 11 s on production. The bug would therefore have shown on staging as about 1 s spikes rather than 10 s. None of the 40 staging requests exceeded 0.253 s. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2221.
Problem
getNeighborGraphrebuiltServer.neighborGraphon the request goroutine once it passed its 5 min TTL. It heldneighborMufor the whole build, which takes 11.1-11.4 s on a production store.The 5 min recomputer went through the same staleness check. A tick that landed just before the TTL skipped the rebuild and left it to the next request. As a result
/api/nodes/{pubkey}/neighborsran at p95 10.4 s and max 11.0 s (57 requests).Change
getNeighborGraphserves the current graph. It builds only when there is none yet, which happens at startup.rebuildNeighborGraphbuilds from the packet store whatever the age of the current graph, outsideneighborMu, and then swaps the pointer.recomputeNeighborGraphCachecalls it first on every tick.neighborBuildMuserializes builds, so a startup request and the first tick do not both build.Freshness is now bounded by the recompute interval (
neighborGraph.cacheRecomputeIntervalSeconds, default 5 min) plus one build. Before this change it was the TTL plus one build, so the bound has not changed. The difference is who pays for the build.IsStale/neighborGraphTTLstay, becausepath_inspect.gostill uses them forstore.graph.Perf
Before:
/api/perfon production shows p95 10404 ms. After: I will add the staging/api/perfnumbers for this endpoint in a comment once it has run for more than one interval.Tests
neighbor_graph_rebuild_test.go:The first and third tests fail on master.
go vetandgo test .pass incmd/server, and-racepasses on the neighbor-graph tests.No frontend change.