Skip to content

Commit

Permalink
Add a plot showing: IB created, linked IB, dropped IB x slot.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadales committed Jul 2, 2024
1 parent de9407b commit 271f4ef
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 24 deletions.
2 changes: 1 addition & 1 deletion leios-sim/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ main = do
, λ = NumberOfSlices 3
, nodeBandwidth = BitsPerSecond 1000
, ibSize = NumberOfBits 300
, f_I = IBFrequency 3
, f_I = IBFrequency 5
, f_E = EBFrequency 1
, initialSeed = 22595838
}
87 changes: 67 additions & 20 deletions leios-sim/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
document.addEventListener('DOMContentLoaded', () => {

// FIXME: these have to be synchronized with the simulation.
var parameters = { L: 4,
λ: 3
}

function sliceOf(slot) {
return Math.floor(slot / parameters.L);
}

const node = document.getElementById('throughput');

// throughput chart
Expand All @@ -11,25 +21,31 @@ document.addEventListener('DOMContentLoaded', () => {
// See for instance: https://medium.com/@allieofisher/inclusive-color-palettes-for-the-web-bbfe8cf2410e
datasets: [
{ type: 'line',
label: "EB throughput",
label: "Created IBs",
data: [],
backgroundColor: '#6FDE6E',
borderColor: '#6FDE6E',
},
{ type: 'line',
label: "Linked IBs",
data: [],
backgroundColor: '#235FA4',
borderColor: '#235FA4',
},
{ type: 'bar',
label: "Queue size",
{ type: 'line',
label: "Dropped IBs",
data: [],
backgroundColor: '#E8F086',
borderColor: '#E8F086',
}
backgroundColor: '#FF4242',
borderColor: '#FF4242',
}
]
},
options: {
scales: {
x: {
type: 'linear',
title: {
text: 'Rounds',
text: 'Slots',
display: true
},
min: 0,
Expand All @@ -39,7 +55,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
});

// retrieve simulation data from server
// Retrieve simulation data from server.
const wsPath = window.location.pathname.split('/').slice(0, -1).join('/');
const ws = new WebSocket("ws://" + window.location.hostname + ":" + window.location.port + wsPath);

Expand All @@ -55,32 +71,62 @@ document.addEventListener('DOMContentLoaded', () => {

ws.onmessage = function(message) {
if (message.data) {

const logData = JSON.parse(message.data);

if (logData.tag == 'ReceivedEB') {
// Keep only the last 50 entries
//
// TODO: find out why the chart won't display properly if this is done after pushing data.
if (chart.data.datasets[0].data.length > 49) {
chart.data.datasets[0].data.splice(0, chart.data.datasets[0].data.length - 49);
}

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);
}
if (logData.tag == 'ReceivedEB') {

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 });
// We know that future EBs will link IBs whose slots are
// greater or equal than the slice linked by the current
// EB. Therefore we can regard all those IBs with smaller
// slots as *lost*.
droppedIBs = queuedIBs.filter(ib =>
sliceOf (ib.ib_slot) < sliceOf(logData.receivedEB.eb_slot) - (parameters.λ + 1)
);

queuedIBs = _.differenceWith(queuedIBs, droppedIBs, _.isEqual);

var i = chart.data.datasets[1].data.findIndex(p => p.x == logData.receivedEB.eb_slot);
if (0 <= i) {
chart.data.datasets[1].data[i] = {x: logData.receivedEB.eb_slot,
y: chart.data.datasets[1].data[i].y + logData.receivedEB.eb_linked_IBs.length};
} else {
chart.data.datasets[1].data.push({ x: logData.receivedEB.eb_slot,
y: logData.receivedEB.eb_linked_IBs.length });
}


chart.data.datasets[2].data.push({ x: logData.receivedEB.eb_slot,
y: droppedIBs.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);

var i = chart.data.datasets[0].data.findIndex(p => p.x == logData.producedIB.ib_slot);
if (0 <= i) {
chart.data.datasets[0].data[i] = {x: logData.producedIB.ib_slot, y: chart.data.datasets[0].data[i].y + 1 };
} else {
chart.data.datasets[0].data.push( {x: logData.producedIB.ib_slot, y: 1});
}

// Adjust the data range
const minx = chart.data.datasets[0].data[0].x;
chart.options.scales.x.min = minx;
chart.options.scales.x.max = minx + 50;
chart.update();
}
}

Expand All @@ -97,6 +143,7 @@ document.addEventListener('DOMContentLoaded', () => {
// handle parameters change
const lambda = document.getElementById('lambda');
lambda.addEventListener('change', function() {
parameters.λ = lambda.value;
postJSON("http://" + window.location.hostname + ":" +
window.location.port + "/api/lambda", parseInt(lambda.value));
});
Expand Down
7 changes: 4 additions & 3 deletions leios-sim/src/Leios/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
-- \* ✅ Allow to pass paremeters to the simulation.
-- \* ✅ Connect with the simulation front end and run.
-- \* ✅ Define a better/more-realistic schedule.
-- \* Tweak the model parameters.
-- \* Add other plots: eg latency distribution.
-- \* ✅ Add a plot showing: IB created, linked IB, dropped IB x slot.
-- \* Tweak the model parameters.
--
-- \* ...
-- \* Implement other roles/phase.
--
Expand Down Expand Up @@ -275,7 +276,7 @@ node nodeId nodeStakePercent initialGenerator tracer world = do
clock <- runClock
let loop generator = do
slot <- nextSlot clock
-- traceWith tracer (NextSlot nodeId slot)
traceWith tracer (NextSlot nodeId slot)
Parameters {f_I, f_E} <- getParams world
-- Generate IB blocks
let (numberOfIBsInThisSlot, generator1) =
Expand Down

0 comments on commit 271f4ef

Please sign in to comment.