Skip to content

Commit

Permalink
Merge #457
Browse files Browse the repository at this point in the history
457: CAD-384:  add mempoolBytes metric r=CodiePP a=deepfire

1. Expose the mempool size (in bytes) as a new metric.
2. Add the metric to the TUI LiveView interface
3. A bit more order in the trace hierarchy.

Co-authored-by: Kosyrev Serge <[email protected]>
  • Loading branch information
iohk-bors[bot] and deepfire authored Jan 13, 2020
2 parents eaed509 + 3a933f1 commit 8d53169
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
38 changes: 35 additions & 3 deletions cardano-node/src/Cardano/Node/TUI/LiveView.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ instance IsEffectuator LiveViewBackend Text where
return $ lvs { lvsMempool = lvsMempool'
, lvsMempoolPerc = percentage
}
LogObject _ _ (LogValue "mempoolBytes" (PureI mempoolBytes)) ->
modifyMVar_ (getbe lvbe) $ \lvs -> do
let lvsMempoolBytes' = fromIntegral mempoolBytes :: Word64
percentage = fromIntegral lvsMempoolBytes' / fromIntegral (lvsMempoolCapacityBytes lvs) :: Float
return $ lvs { lvsMempoolBytes = lvsMempoolBytes'
, lvsMempoolBytesPerc = percentage
}
LogObject _ _ (LogValue "density" (PureD density)) ->
modifyMVar_ (getbe lvbe) $ \lvs ->
return $ lvs { lvsChainDensity = 0.05 + density * 100.0 }
Expand Down Expand Up @@ -246,6 +253,8 @@ data LiveViewState a = LiveViewState
, lvsPeersConnected :: Word64
, lvsMempool :: Word64
, lvsMempoolPerc :: Float
, lvsMempoolBytes :: Word64
, lvsMempoolBytesPerc :: Float
, lvsCPUUsagePerc :: Float
, lvsMemoryUsageCurr :: Float
, lvsMemoryUsageMax :: Float
Expand Down Expand Up @@ -274,6 +283,7 @@ data LiveViewState a = LiveViewState
, lvsNetworkUsageOutLast :: Word64
, lvsNetworkUsageOutNs :: Word64
, lvsMempoolCapacity :: Word64
, lvsMempoolCapacityBytes :: Word64
, lvsMessage :: Maybe a
, lvsUIThread :: Maybe (Async.Async ())
, lvsMetricsThread :: Maybe (Async.Async ())
Expand All @@ -284,6 +294,11 @@ data LiveViewState a = LiveViewState
initLiveViewState :: IO (LiveViewState a)
initLiveViewState = do
now <- getCurrentTime

let -- TODO: obtain from configuration
mempoolCapacity = 200 :: Word64
maxBytesPerTx = 4096 :: Word64

return $ LiveViewState
{ lvsQuit = False
, lvsRelease = "Shelley"
Expand All @@ -300,6 +315,8 @@ initLiveViewState = do
, lvsPeersConnected = 0
, lvsMempool = 0
, lvsMempoolPerc = 0.0
, lvsMempoolBytes = 0
, lvsMempoolBytesPerc = 0.0
, lvsCPUUsagePerc = 0.58
, lvsMemoryUsageCurr = 0.0
, lvsMemoryUsageMax = 0.2
Expand All @@ -326,7 +343,8 @@ initLiveViewState = do
, lvsNetworkUsageInNs = 10000
, lvsNetworkUsageOutLast = 0
, lvsNetworkUsageOutNs = 10000
, lvsMempoolCapacity = 200
, lvsMempoolCapacity = mempoolCapacity
, lvsMempoolCapacityBytes = mempoolCapacity * maxBytesPerTx
, lvsMessage = Nothing
, lvsUIThread = Nothing
, lvsMetricsThread = Nothing
Expand Down Expand Up @@ -540,14 +558,19 @@ headerW p =

systemStatsW :: LiveViewState a -> Widget ()
systemStatsW p =
padTop (T.Pad 2)
padTop (T.Pad 1)
. padLeft (T.Pad 2)
. padRight (T.Pad 2)
$ vBox [ vBox [ hBox [ padBottom (T.Pad 1) $ txt "Mempool:"
$ vBox [ vBox [ hBox [ txt "Mempool txs:"
, withAttr barValueAttr . padLeft T.Max . str . show $ lvsMempoolCapacity p
]
, padBottom (T.Pad 1) memPoolBar
]
, vBox [ hBox [ txt "Mempool bytes:"
, withAttr barValueAttr . padLeft T.Max . str . show $ lvsMempoolCapacityBytes p
]
, padBottom (T.Pad 1) memPoolBytesBar
]
, vBox [ hBox [ txt "Memory usage:"
, withAttr barValueAttr . padLeft T.Max $ str $ (take 5 $ show $ max (lvsMemoryUsageMax p) 200.0) <> " MB"
]
Expand Down Expand Up @@ -594,6 +617,15 @@ systemStatsW p =
mempoolLabel = Just $ (show . lvsMempool $ p)
++ " / "
++ take 5 (show $ lvsMempoolPerc p * 100) ++ "%"
memPoolBytesBar :: forall n. Widget n
memPoolBytesBar = updateAttrMap
(A.mapAttrNames [ (mempoolDoneAttr, P.progressCompleteAttr)
, (mempoolToDoAttr, P.progressIncompleteAttr)
]
) $ bar mempoolBytesLabel (lvsMempoolBytesPerc p)
mempoolBytesLabel = Just $ (show . lvsMempoolBytes $ p)
++ " / "
++ take 5 (show $ lvsMempoolBytesPerc p * 100) ++ "%"
memUsageBar :: forall n. Widget n
memUsageBar = updateAttrMap
(A.mapAttrNames [ (memDoneAttr, P.progressCompleteAttr)
Expand Down
5 changes: 5 additions & 0 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ mkTracers traceOptions tracer = do
logValue2 :: LOContent a
logValue2 = LogValue "txsProcessed" $ PureI $ fromIntegral n

logValue3 :: LOContent a
logValue3 = LogValue "mempoolBytes" $ PureI $ fromIntegral (msNumBytes tot)

meta <- mkLOMeta Critical Confidential

traceNamedObject tr (meta, logValue1)
Expand All @@ -288,6 +291,8 @@ mkTracers traceOptions tracer = do
traceNamedObject tr (meta, logValue2)
traceNamedObject tr' (meta, logValue2)

traceNamedObject tr (meta, logValue3)
traceNamedObject tr' (meta, logValue3)

mempoolTracer :: Tracer IO (TraceEventMempool blk)
mempoolTracer = Tracer $ \ev -> do
Expand Down

0 comments on commit 8d53169

Please sign in to comment.