-
Notifications
You must be signed in to change notification settings - Fork 755
CDFs for EB announcements #6639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: leios-prototype
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| {-# LANGUAGE NamedFieldPuns #-} | ||
| {-# LANGUAGE RecordWildCards #-} | ||
| {-# LANGUAGE ScopedTypeVariables #-} | ||
|
|
||
| -- | CDFs | ||
| -- | ||
| -- This module should be imported qualified. | ||
| -- | ||
| module Cardano.Node.Tracing.Cdf | ||
| ( Counter (..) | ||
| , Config (..) | ||
| , State | ||
| , size | ||
| , null | ||
| , empty | ||
| , minPriority | ||
| , defaultConfig | ||
| , processDataPoint | ||
| ) where | ||
|
|
||
| import Prelude hiding (null) | ||
| import Data.Int (Int64) | ||
| import Data.IntPSQ (IntPSQ) | ||
| import qualified Data.IntPSQ as Pq | ||
| import Data.Time (NominalDiffTime) | ||
|
|
||
| data Counter = Counter { | ||
| limit :: !Double | ||
| , counter :: !Int64 | ||
| } | ||
|
|
||
| decCdf :: Double -> Counter -> Counter | ||
| decCdf v cdf@Counter{..} | ||
| | v < limit = cdf {counter = counter - 1} | ||
| | otherwise = cdf | ||
|
|
||
| incCdf :: Double -> Counter -> Counter | ||
| incCdf v cdf@Counter{..} | ||
| | v < limit = cdf {counter = counter + 1} | ||
| | otherwise = cdf | ||
|
|
||
|
|
||
| newtype State p = State { cdfState :: IntPSQ p NominalDiffTime } | ||
|
|
||
| empty :: State p | ||
| empty = State Pq.empty | ||
|
|
||
| null :: State p -> Bool | ||
| null = Pq.null . cdfState | ||
|
|
||
| size :: State p -> Int | ||
| size = Pq.size . cdfState | ||
|
|
||
| minPriority :: Ord p => State p -> Maybe p | ||
| minPriority State { cdfState } = case Pq.minView cdfState of | ||
| Nothing -> Nothing | ||
| Just (_, p, _, _) -> Just p | ||
|
|
||
| data Config = Config { numOfDataPoints :: Int } | ||
|
Check warning on line 59 in cardano-node/src/Cardano/Node/Tracing/Cdf.hs
|
||
|
|
||
| -- | Default `Config` keeps `k/2` data points. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The proportionality to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But one other option is to just force each callers to choose a number |
||
| defaultConfig :: Config | ||
| defaultConfig = Config { numOfDataPoints = 1080 } | ||
|
|
||
|
|
||
| processDataPoint | ||
| :: forall f p. | ||
| ( Ord p | ||
| , Functor f | ||
| ) | ||
| => Config | ||
| -> (Int, p, NominalDiffTime) | ||
| -- ^ index, priority, value | ||
| -> State p | ||
| -> f Counter | ||
| -> (f Counter, State p, Bool) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple questions that a comment should answer:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's only two call sites to this function and they both ignore the return value when the returned So return |
||
| processDataPoint Config { numOfDataPoints } (idx, p, delay) s@(State m) cdfs | ||
| | idx `Pq.member` m | ||
| = nothingToDo | ||
|
|
||
| | otherwise | ||
| = if Pq.size m' > numOfDataPoints | ||
| then | ||
| case Pq.minView m' of | ||
| Nothing -> (cdfs, s, False) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
| Just (_, minVal, minDelay, m'') | ||
| | minVal == p | ||
| -> nothingToDo | ||
|
|
||
| | otherwise | ||
| -> (adjustCdf (realToFrac minDelay) <$> cdfs, State m'', True) | ||
| else | ||
| (updateCdf <$> cdfs, State m', True) | ||
| where | ||
| nothingToDo = (cdfs, s, False) | ||
|
|
||
| delay_ :: Double | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just inline this as |
||
| delay_ = realToFrac delay | ||
|
|
||
| m' = Pq.insert idx p delay m | ||
|
|
||
| updateCdf :: Counter -> Counter | ||
| updateCdf = incCdf delay_ | ||
|
|
||
| adjustCdf :: Double -> Counter -> Counter | ||
| adjustCdf d = updateCdf . decCdf d | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,8 @@ import qualified Ouroboros.Network.BlockFetch.ClientState as BlockFetch | |||||||||||||||||||
| import Ouroboros.Network.ConnectionId (ConnectionId) | ||||||||||||||||||||
| import qualified Ouroboros.Network.Diffusion as Diffusion | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import LeiosDemoTypes (TraceLeiosKernel (..)) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import Codec.CBOR.Read (DeserialiseFailure) | ||||||||||||||||||||
| import Control.Monad (unless) | ||||||||||||||||||||
| import "contra-tracer" Control.Tracer (mkTracer) | ||||||||||||||||||||
|
|
@@ -360,6 +362,15 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf | |||||||||||||||||||
| ["Consensus", "LeiosKernel"] | ||||||||||||||||||||
| configureTracers configReflection trConfig [leiosKernelTr] | ||||||||||||||||||||
|
|
||||||||||||||||||||
| !leiosMetricsTr <- do | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Matches the extant pattern, eg: cardano-node/cardano-node/src/Cardano/Node/Tracing/Tracers.hs Lines 258 to 266 in ee7ea74
|
||||||||||||||||||||
| tr1 <- foldTraceM (\cm lc -> pure . calculateLeiosMetrics cm lc) initialLeiosMetrics | ||||||||||||||||||||
| (metricsFormatter | ||||||||||||||||||||
| (mkMetricsTracer mbTrEKG)) | ||||||||||||||||||||
| pure $ filterTrace (\(_, msg) -> case msg of | ||||||||||||||||||||
| TraceLeiosAnnouncementAccepted{} -> True | ||||||||||||||||||||
| _ -> False) | ||||||||||||||||||||
| tr1 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| !leiosPeerTr <- mkCardanoTracer | ||||||||||||||||||||
| trBase trForward mbTrEKG | ||||||||||||||||||||
| ["Consensus", "LeiosPeer"] | ||||||||||||||||||||
|
|
@@ -421,6 +432,7 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf | |||||||||||||||||||
| traceWith txCountersTracer | ||||||||||||||||||||
| , Consensus.leiosKernelTracer = mkTracer $ | ||||||||||||||||||||
| traceWith leiosKernelTr | ||||||||||||||||||||
| <> traceWith leiosMetricsTr | ||||||||||||||||||||
| , Consensus.leiosPeerTracer = mkTracer $ | ||||||||||||||||||||
| traceWith leiosPeerTr | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment explaining why a Cdf needs a notion of priority?