Skip to content

Commit

Permalink
Add support for plotting the IB queue size.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadales committed Jun 26, 2024
1 parent 998c796 commit 6ce5995
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
1 change: 1 addition & 0 deletions leios-sim/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>Leios</title>
<link rel="stylesheet" href="leios.css" >
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
<script src="index.js"></script>
</head>
<body>
Expand Down
53 changes: 37 additions & 16 deletions leios-sim/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ document.addEventListener('DOMContentLoaded', () => {
text: "Leios Blocks throughput"
},
data: {
datasets: [{
type: 'bar',
label: "Queue size",
data: []
}, {
type: 'line',
label: "EB throughput",
data: []
}]
// N.B.: Make sure colors are picked from an inclusive color palette.
// See for instance: https://medium.com/@allieofisher/inclusive-color-palettes-for-the-web-bbfe8cf2410e
datasets: [
{ type: 'line',
label: "EB throughput",
data: [],
backgroundColor: '#235FA4',
borderColor: '#235FA4',
},
{ type: 'bar',
label: "Queue size",
data: [],
backgroundColor: '#E8F086',
borderColor: '#E8F086',
}
]
},
options: {
scales: {
Expand All @@ -40,29 +47,43 @@ document.addEventListener('DOMContentLoaded', () => {
console.log('connected');
};

// We will add elements to the queue when we get a log message about
// a new IB being created. When we receive a log message about a
// created EB, we will remove the linked IBs inside the EB from the
// queue.
var queuedIBs = [];

ws.onmessage = function(message) {
if (message.data) {
const eb = JSON.parse(message.data);

if (eb.tag == 'ReceivedEB') {
const logData = JSON.parse(message.data);

if (logData.tag == 'ReceivedEB') {

if (chart.data.datasets[0].data.length > 49) {
chart.data.datasets[0].data.splice(0, chart.data.datasets[0].data.length - 49);
chart.data.datasets[1].data.splice(0, chart.data.datasets[1].data.length - 49);
}

// TODO: determine the queue size
chart.data.datasets[0].data.push({ x: eb.receivedEB.eb_slot, y: 0 });
console.log (eb.receivedEB);
console.log (eb.receivedEB.eb_slot);
if (logData.receivedEB.eb_linked_IBs.length != 0) {
queuedIBs = _.differenceWith(queuedIBs, logData.receivedEB.eb_linked_IBs, _.isEqual);
}

chart.data.datasets[0].data.push({ x: logData.receivedEB.eb_slot,
y: logData.receivedEB.eb_linked_IBs.length });
chart.data.datasets[1].data.push({ x: logData.receivedEB.eb_slot, y: queuedIBs.length });

chart.data.datasets[1].data.push({ x: eb.receivedEB.eb_slot, y: eb.receivedEB.eb_linked_IBs.length });
const minx = chart.data.datasets[0].data[0].x;
chart.options.scales.x.min = minx;
chart.options.scales.x.max = minx + 50;
chart.update();
}

if (logData.tag == 'ProducedIB') {
queuedIBs.push(logData.producedIB);
}
}

};

window.onbeforeunload = _ => {
Expand Down
19 changes: 13 additions & 6 deletions leios-sim/src/Leios/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import qualified Data.PQueue.Max as PQueue
import GHC.Generics (Generic)
import Leios.Trace (mkTracer)
import Text.Pretty.Simple (pPrint)
import Data.List (partition)

--------------------------------------------------------------------------------
-- FIXME: constants that should be configurable
Expand Down Expand Up @@ -469,13 +470,19 @@ storeIB nodeId ib OutsideWorld{storedIBsTVar} =
atomically $
modifyTVar' storedIBsTVar (Map.alter (Just . maybe [ib] (ib :)) nodeId)

-- | Retrieve the downloaded IBs by the given node, which correspond to the given slice.
-- | Retrieve the downloaded IBs by the given node, which correspond
-- to the given slice. Once retrieved the IBs are deleted.
--
storedIBsBy :: MonadSTM m => NodeId -> OutsideWorld m -> Slice -> m [IB]
storedIBsBy nodeId OutsideWorld{storedIBsTVar} slice = do
mStoredIBs <- atomically (readTVar storedIBsTVar)
pure $
maybe [] (filter ((`isWithin` slice) . ib_slot)) $
Map.lookup nodeId mStoredIBs
storedIBsBy nodeId OutsideWorld{storedIBsTVar} slice = atomically $ do
storedIBs <- readTVar storedIBsTVar
case Map.lookup nodeId storedIBs of
Nothing -> pure []
Just nodeIdStoredIBs -> do
let (ibsWithinSlice, ibsOutsideSlice) =
partition ((`isWithin` slice) . ib_slot) nodeIdStoredIBs
writeTVar storedIBsTVar (Map.insert nodeId ibsOutsideSlice storedIBs)
pure ibsWithinSlice

--------------------------------------------------------------------------------
-- A priority queue inside a transactional var
Expand Down

0 comments on commit 6ce5995

Please sign in to comment.