Skip to content

Commit

Permalink
peer-selection: removed localRoots from counters
Browse files Browse the repository at this point in the history
`localRoots` didn't count local connections, but the targets. We don't
expose other targets in EKG metrics, so there's no reason to actually
include local root targets.
  • Loading branch information
coot committed May 7, 2024
1 parent 88d585e commit 38d17e4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3302,7 +3302,7 @@ selectGovState :: Eq a
selectGovState f =
Signal.nub
-- TODO: #3182 Rng seed should come from quickcheck.
. Signal.fromChangeEvents (f $! Governor.emptyPeerSelectionState (mkStdGen 42) [])
. Signal.fromChangeEvents (f $! Governor.emptyPeerSelectionState (mkStdGen 42))
. Signal.selectEvents
(\case GovernorDebug (TraceGovernorState _ _ st) -> Just $! f st
_ -> Nothing)
Expand Down Expand Up @@ -3346,8 +3346,8 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap
readDomains
(ioDNSActions LookupReqAAndAAAA) $ \requestPublicRootPeers -> do
publicStateVar <- makePublicPeerSelectionStateVar
debugVar <- newTVarIO $ emptyPeerSelectionState (mkStdGen 42) []
countersVar <- newTVarIO $ emptyPeerSelectionCounters []
debugVar <- newTVarIO $ emptyPeerSelectionState (mkStdGen 42)
countersVar <- newTVarIO emptyPeerSelectionCounters
peerSelectionGovernor
tracer tracer tracer
-- TODO: #3182 Rng seed should come from quickcheck.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ governorAction mockEnv = do
(ledgerStateJudgement mockEnv)
usbVar <- playTimedScript (contramap TraceEnvSetUseBootstrapPeers tracerMockEnv)
(useBootstrapPeers mockEnv)
debugVar <- StrictTVar.newTVarIO (emptyPeerSelectionState (mkStdGen 42) [])
countersVar <- StrictTVar.newTVarIO (emptyPeerSelectionCounters [])
debugVar <- StrictTVar.newTVarIO (emptyPeerSelectionState (mkStdGen 42))
countersVar <- StrictTVar.newTVarIO emptyPeerSelectionCounters
policy <- mockPeerSelectionPolicy mockEnv
actions <- mockPeerSelectionActions tracerMockEnv mockEnv (readTVar usbVar) (readTVar lsjVar) policy
exploreRaces -- explore races within the governor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3875,7 +3875,7 @@ selectDiffusionPeerSelectionState :: Eq a
selectDiffusionPeerSelectionState f =
Signal.nub
-- TODO: #3182 Rng seed should come from quickcheck.
. Signal.fromChangeEvents (f $ Governor.emptyPeerSelectionState (mkStdGen 42) [])
. Signal.fromChangeEvents (f $ Governor.emptyPeerSelectionState (mkStdGen 42))
. Signal.selectEvents
(\case
DiffusionDebugPeerSelectionTrace (TraceGovernorState _ _ st) -> Just (f st)
Expand All @@ -3887,7 +3887,7 @@ selectDiffusionPeerSelectionState' :: Eq a
-> Signal a
selectDiffusionPeerSelectionState' f =
-- TODO: #3182 Rng seed should come from quickcheck.
Signal.fromChangeEvents (f $ Governor.emptyPeerSelectionState (mkStdGen 42) [])
Signal.fromChangeEvents (f $ Governor.emptyPeerSelectionState (mkStdGen 42))
. Signal.selectEvents
(\case
DiffusionDebugPeerSelectionTrace (TraceGovernorState _ _ st) -> Just (f st)
Expand Down
6 changes: 3 additions & 3 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ runM Interfaces
min 2 (targetNumberOfActivePeers daPeerSelectionTargets)
}

countersVar <- newTVarIO (emptyPeerSelectionCounters [])
countersVar <- newTVarIO emptyPeerSelectionCounters

-- Design notes:
-- - We split the following code into two parts:
Expand Down Expand Up @@ -1064,7 +1064,7 @@ runM Interfaces
-- InitiatorOnly mode, run peer selection only:
InitiatorOnlyDiffusionMode ->
withConnectionManagerInitiatorOnlyMode $ \connectionManager-> do
debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng []
debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng
diInstallSigUSR1Handler connectionManager debugStateVar daPeerMetrics
withPeerStateActions' connectionManager $ \peerStateActions->
withPeerSelectionActions'
Expand All @@ -1089,7 +1089,7 @@ runM Interfaces
inboundInfoChannel $ \connectionManager->
withSockets' $ \sockets addresses -> do
withServer sockets connectionManager inboundInfoChannel $ \inboundGovernorThread readInboundState -> do
debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng []
debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng
diInstallSigUSR1Handler connectionManager debugStateVar daPeerMetrics
withPeerStateActions' connectionManager $ \peerStateActions ->
withPeerSelectionActions'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,7 @@ peerSelectionGovernor :: ( Alternative (STM m)
-> PeerSelectionPolicy peeraddr m
-> m Void
peerSelectionGovernor tracer debugTracer countersTracer fuzzRng countersVar publicStateVar debugStateVar actions policy =
JobPool.withJobPool $ \jobPool -> do
localPeers <- map (\(w, h, _) -> (w, h))
<$> atomically (readLocalRootPeers actions)
JobPool.withJobPool $ \jobPool ->
peerSelectionGovernorLoop
tracer
debugTracer
Expand All @@ -472,7 +470,7 @@ peerSelectionGovernor tracer debugTracer countersTracer fuzzRng countersVar publ
actions
policy
jobPool
(emptyPeerSelectionState fuzzRng localPeers)
(emptyPeerSelectionState fuzzRng)

-- | Our pattern here is a loop with two sets of guarded actions:
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Ouroboros.Network.PeerSelection.Governor.Types
, TimedDecision
, MkGuardedDecision
, Completion (..)
, PeerSelectionCounters (.., PeerSelectionCountersHWC, numberOfColdPeers, numberOfWarmPeers, numberOfHotPeers, numberOfColdBigLedgerPeers, numberOfWarmBigLedgerPeers, numberOfHotBigLedgerPeers, numberOfColdLocalRootPeers, numberOfWarmLocalRootPeers, numberOfHotLocalRootPeers, localRootsHWC)
, PeerSelectionCounters (.., PeerSelectionCountersHWC, numberOfColdPeers, numberOfWarmPeers, numberOfHotPeers, numberOfColdBigLedgerPeers, numberOfWarmBigLedgerPeers, numberOfHotBigLedgerPeers, numberOfColdLocalRootPeers, numberOfWarmLocalRootPeers, numberOfHotLocalRootPeers)
, emptyPeerSelectionCounters
, peerSelectionStateToCounters
-- * Peer Sharing Auxiliary data type
Expand Down Expand Up @@ -633,11 +633,6 @@ data PeerSelectionCounters = PeerSelectionCounters {
numberOfActiveLocalRootPeers :: Int,
numberOfActiveLocalRootPeersDemotions :: Int,

-- | Local root peers with one entry per group. First entry is the number
-- of warm peers in that group the second is the number of hot peers in
-- that group.
localRoots :: ![(HotValency, WarmValency)],

--
-- Share Peers
-- (peers received through peer sharing)
Expand Down Expand Up @@ -671,7 +666,6 @@ data PeerSelectionCounters = PeerSelectionCounters {
pattern PeerSelectionCountersHWC :: Int -> Int -> Int -- peers
-> Int -> Int -> Int -- big ledger peers
-> Int -> Int -> Int -- local roots
-> [(HotValency, WarmValency)]
-> PeerSelectionCounters
pattern PeerSelectionCountersHWC { numberOfColdPeers,
numberOfWarmPeers,
Expand All @@ -683,8 +677,7 @@ pattern PeerSelectionCountersHWC { numberOfColdPeers,

numberOfColdLocalRootPeers,
numberOfWarmLocalRootPeers,
numberOfHotLocalRootPeers,
localRootsHWC }
numberOfHotLocalRootPeers }

<- (peerSelectionCountersHWC ->
PeerSelectionCounters { numberOfKnownPeers = numberOfColdPeers,
Expand All @@ -697,8 +690,8 @@ pattern PeerSelectionCountersHWC { numberOfColdPeers,

numberOfKnownLocalRootPeers = numberOfColdLocalRootPeers,
numberOfEstablishedLocalRootPeers = numberOfWarmLocalRootPeers,
numberOfActiveLocalRootPeers = numberOfHotLocalRootPeers,
localRoots = localRootsHWC })
numberOfActiveLocalRootPeers = numberOfHotLocalRootPeers
})

{-# COMPLETE PeerSelectionCountersHWC #-}

Expand Down Expand Up @@ -738,8 +731,6 @@ peerSelectionCountersHWC PeerSelectionCounters {..} =
numberOfActiveLocalRootPeers,
numberOfActiveLocalRootPeersDemotions,

localRoots,

numberOfKnownSharedPeers = numberOfKnownSharedPeers
- numberOfEstablishedSharedPeers,
numberOfColdSharedPeersPromotions,
Expand Down Expand Up @@ -810,8 +801,6 @@ peerSelectionStateToCounters
numberOfActiveLocalRootPeers = Set.size activeLocalRootsPeersSet,
numberOfActiveLocalRootPeersDemotions = Set.size $ activeLocalRootsPeersSet `Set.intersection` inProgressDemoteHot,

localRoots,

numberOfKnownSharedPeers = Set.size knownSharedPeersSet,
numberOfColdSharedPeersPromotions = Set.size $ knownSharedPeersSet `Set.intersection` inProgressPromoteCold,
numberOfEstablishedSharedPeers = Set.size establishedSharedPeersSet,
Expand Down Expand Up @@ -844,10 +833,6 @@ peerSelectionStateToCounters
activeBigLedgerPeersSet = activePeers `Set.intersection` bigLedgerSet

-- local roots
localRoots =
[ (hot, warm)
| (hot, warm, _) <- LocalRootPeers.toGroupSets localRootPeers
]
localRootSet = LocalRootPeers.keysSet localRootPeers
-- local roots and big ledger peers are disjoint, hence we can use
-- `knownPeersSet`, `establishedPeersSet` and `activePeersSet` below.
Expand All @@ -872,9 +857,8 @@ peerSelectionStateToCounters



emptyPeerSelectionCounters :: [(HotValency, WarmValency)]
-> PeerSelectionCounters
emptyPeerSelectionCounters localRoots =
emptyPeerSelectionCounters :: PeerSelectionCounters
emptyPeerSelectionCounters =
PeerSelectionCounters {
numberOfRootPeers = 0,

Expand Down Expand Up @@ -908,8 +892,6 @@ emptyPeerSelectionCounters localRoots =
numberOfActiveLocalRootPeers = 0,
numberOfActiveLocalRootPeersDemotions = 0,

localRoots,

numberOfKnownSharedPeers = 0,
numberOfColdSharedPeersPromotions = 0,
numberOfEstablishedSharedPeers = 0,
Expand All @@ -920,9 +902,8 @@ emptyPeerSelectionCounters localRoots =
}

emptyPeerSelectionState :: StdGen
-> [(HotValency, WarmValency)]
-> PeerSelectionState peeraddr peerconn
emptyPeerSelectionState rng localRoots =
emptyPeerSelectionState rng =
PeerSelectionState {
targets = nullPeerSelectionTargets,
localRootPeers = LocalRootPeers.empty,
Expand All @@ -943,7 +924,7 @@ emptyPeerSelectionState rng localRoots =
inProgressDemoteHot = Set.empty,
inProgressDemoteToCold = Set.empty,
stdGen = rng,
countersCache = Cache (emptyPeerSelectionCounters localRoots),
countersCache = Cache emptyPeerSelectionCounters,
ledgerStateJudgement = TooOld,
bootstrapPeersFlag = DontUseBootstrapPeers,
hasOnlyBootstrapPeers = False,
Expand Down

0 comments on commit 38d17e4

Please sign in to comment.