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 Apr 16, 2024
1 parent 823b611 commit c8be76b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 41 deletions.
Expand Up @@ -3292,7 +3292,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 @@ -3336,8 +3336,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
Expand Up @@ -210,8 +210,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
Expand Up @@ -3871,7 +3871,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 @@ -3883,7 +3883,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
Expand Up @@ -808,7 +808,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 @@ -1062,7 +1062,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 Down Expand Up @@ -1090,7 +1090,7 @@ runM Interfaces
inboundInfoChannel
outboundInfoChannel
observableStateVar $ \connectionManager-> do
debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng []
debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng
diInstallSigUSR1Handler connectionManager debugStateVar daPeerMetrics
withPeerStateActions' connectionManager $ \peerStateActions ->
withPeerSelectionActions'
Expand Down
Expand Up @@ -457,9 +457,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 @@ -470,7 +468,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
Expand Up @@ -37,7 +37,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 @@ -623,11 +623,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 @@ -661,7 +656,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 @@ -673,8 +667,7 @@ pattern PeerSelectionCountersHWC { numberOfColdPeers,

numberOfColdLocalRootPeers,
numberOfWarmLocalRootPeers,
numberOfHotLocalRootPeers,
localRootsHWC }
numberOfHotLocalRootPeers }

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

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

{-# COMPLETE PeerSelectionCountersHWC #-}

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

localRoots,

numberOfKnownSharedPeers = numberOfKnownSharedPeers
- numberOfEstablishedSharedPeers,
numberOfColdSharedPeersPromotions,
Expand Down Expand Up @@ -800,8 +791,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 @@ -834,10 +823,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 @@ -862,9 +847,8 @@ peerSelectionStateToCounters



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

Expand Down Expand Up @@ -898,8 +882,6 @@ emptyPeerSelectionCounters localRoots =
numberOfActiveLocalRootPeers = 0,
numberOfActiveLocalRootPeersDemotions = 0,

localRoots,

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

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

0 comments on commit c8be76b

Please sign in to comment.