Skip to content
Snippets Groups Projects
Commit 140128fb authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Added network->frontend benchmark to sequential dots

parent 3fab2647
No related branches found
No related tags found
No related merge requests found
......@@ -31,16 +31,21 @@ function printBenchmark(title, iterations, results) {
process.stdout.write(`\n ${title} (${iterations} iterations):\n`)
for (const title in results) {
const { time, packets, size } = results[title]
const { timeLoc, packets, size, timeRem, events } = results[title]
const synchronisation = title == "synchronisation"
process.stdout.write(
chalk` {yellow ⧗} {dim ${title}:} {yellow.inverse ${(
time /
timeLoc /
(1e6 * (synchronisation ? 1 : iterations))
).toFixed(3)}ms ${
synchronisation ? "total" : "/ it"
}} {magenta.inverse ${size}B} {dim in ${packets} packet(s)}\n`,
}} => {dim ${packets} packet(s)} => {magenta.inverse ${size}B} => {yellow.inverse ${(
timeRem /
(1e6 * (synchronisation ? 1 : iterations))
).toFixed(3)}ms ${
synchronisation ? "total" : "/ it"
}} => {dim ${events} event(s)}\n`,
)
}
......@@ -96,23 +101,30 @@ describe("drawing app mesh", () => {
it("benchmarks a single draw and erase update sequentially", () => {
const ITERATIONS = 1000
jest.setTimeout(ITERATIONS * 10)
jest.setTimeout(ITERATIONS * (10 + 300))
const dotIDs = []
let prevTime
let broadcasts = 0
let addTime = 0
let addPackets = 0
let addLocTime = 0
const addPackets = []
let addSize = 0
let eraseTime = 0
let erasePackets = 0
let eraseLocTime = 0
const erasePackets = []
let eraseSize = 0
let syncTime
let syncPackets = 0
let syncLocTime
const syncPackets = []
let syncSize = 0
let addRemTime = 0
let addEvents = 0
let eraseRemTime = 0
let eraseEvents = 0
let syncRemTime = 0
let syncEvents = 0
let timeout
return new Promise((resolve) => {
......@@ -122,14 +134,14 @@ describe("drawing app mesh", () => {
broadcasts += 1
if (broadcasts <= ITERATIONS) {
addTime +=
addLocTime +=
(currTime[0] - prevTime[0]) * 1e9 + (currTime[1] - prevTime[1])
addPackets += 1
addPackets.push(message)
addSize += message.message.length
} else {
eraseTime +=
eraseLocTime +=
(currTime[0] - prevTime[0]) * 1e9 + (currTime[1] - prevTime[1])
erasePackets += 1
erasePackets.push(message)
eraseSize += message.message.length
}
......@@ -151,45 +163,159 @@ describe("drawing app mesh", () => {
prevTime = process.hrtime()
dotIDs.push(room.addPath(dotDraw[0]))
}).then(
() =>
new Promise((resolve) => {
sendListener.callback = (uid, channel, message) => {
const currTime = process.hrtime()
syncTime =
(currTime[0] - prevTime[0]) * 1e9 + (currTime[1] - prevTime[1])
})
.then(
() =>
new Promise((resolve) => {
sendListener.callback = (uid, channel, message) => {
const currTime = process.hrtime()
syncLocTime =
(currTime[0] - prevTime[0]) * 1e9 + (currTime[1] - prevTime[1])
syncPackets += 1
syncSize += message.message.length
syncPackets.push(message)
syncSize += message.message.length
clearTimeout(timeout)
timeout = setTimeout(() => {
printBenchmark("single draw and erase [sequential]", ITERATIONS, {
addPath: { time: addTime, packets: addPackets, size: addSize },
extendErasureIntervals: {
time: eraseTime,
packets: erasePackets,
size: eraseSize,
},
synchronisation: {
time: syncTime,
packets: syncPackets,
size: syncSize,
},
})
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
}
resolve()
}, 1000)
}
prevTime = process.hrtime()
prevTime = process.hrtime()
getEventListener(
"room",
"messageReceived",
)(createMessageReceivedEvent(syncStep1))
}),
)
.then(
() =>
new Promise((resolve) => {
broadcasts = 0
let currTime
const timeoutCallback = () => {
broadcasts += 1
// TODO: can we assume that we only use one message here?
if (broadcasts <= ITERATIONS) {
addRemTime +=
(currTime[0] - prevTime[0]) * 1e9 +
(currTime[1] - prevTime[1])
} else {
eraseRemTime +=
(currTime[0] - prevTime[0]) * 1e9 +
(currTime[1] - prevTime[1])
}
getEventListener(
"room",
"messageReceived",
)(createMessageReceivedEvent(syncStep1))
}),
)
let packet
if (broadcasts < ITERATIONS) {
packet = addPackets[broadcasts]
} else if (broadcasts < ITERATIONS * 2) {
packet = erasePackets[broadcasts - ITERATIONS]
} else {
resolve()
}
prevTime = process.hrtime()
getEventListener(
"update",
"messageReceived",
)(createMessageReceivedEvent(packet))
}
updateRoom.addEventListener("addOrUpdatePath", () => {
currTime = process.hrtime()
addEvents += 1
clearTimeout(timeout)
timeout = setTimeout(timeoutCallback, 100)
})
updateRoom.addEventListener("removedIntervalsChange", () => {
currTime = process.hrtime()
if (broadcasts < ITERATIONS) {
addEvents += 1
} else if (broadcasts < ITERATIONS * 2) {
eraseEvents += 1
}
clearTimeout(timeout)
timeout = setTimeout(timeoutCallback, 100)
})
prevTime = process.hrtime()
getEventListener(
"update",
"messageReceived",
)(createMessageReceivedEvent(addPackets[0]))
}),
)
.then(
() =>
new Promise((resolve) => {
syncRoom.addEventListener("addOrUpdatePath", () => {
const currTime = process.hrtime()
syncRemTime =
(currTime[0] - prevTime[0]) * 1e9 + (currTime[1] - prevTime[1])
syncEvents += 1
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
})
syncRoom.addEventListener("removedIntervalsChange", () => {
const currTime = process.hrtime()
syncRemTime =
(currTime[0] - prevTime[0]) * 1e9 + (currTime[1] - prevTime[1])
syncEvents += 1
clearTimeout(timeout)
timeout = setTimeout(() => resolve(), 1000)
})
prevTime = process.hrtime()
for (const syncPacket of syncPackets) {
getEventListener(
"sync",
"messageReceived",
)(createMessageReceivedEvent(syncPacket))
}
}),
)
.then(() => {
printBenchmark("single draw and erase [sequential]", ITERATIONS, {
addPath: {
timeLoc: addLocTime,
packets: addPackets.length,
size: addSize,
timeRem: addRemTime,
events: addEvents,
},
extendErasureIntervals: {
timeLoc: eraseLocTime,
packets: erasePackets.length,
size: eraseSize,
timeRem: eraseRemTime,
events: eraseEvents,
},
synchronisation: {
timeLoc: syncLocTime,
packets: syncPackets.length,
size: syncSize,
timeRem: syncRemTime,
events: syncEvents,
},
})
})
})
it("benchmarks a single draw and erase update in parallel", () => {
......@@ -274,19 +400,25 @@ describe("drawing app mesh", () => {
timeout = setTimeout(() => {
printBenchmark("single draw and erase [parallel]", ITERATIONS, {
addPath: {
time: addTime,
timeLoc: addTime,
packets: addPackets,
size: addSize,
timeRem: -1,
events: -1,
},
extendErasureIntervals: {
time: eraseTime,
timeLoc: eraseTime,
packets: erasePackets,
size: eraseSize,
timeRem: -1,
events: -1,
},
synchronisation: {
time: syncTime,
timeLoc: syncTime,
packets: syncPackets,
size: syncSize,
timeRem: -1,
events: -1,
},
})
......@@ -598,16 +730,26 @@ describe("drawing app mesh", () => {
clearTimeout(timeout)
timeout = setTimeout(() => {
printBenchmark("path draw and erase [sequential]", ITERATIONS, {
addPath: { time: addTime, packets: addPackets, size: addSize },
addPath: {
timeLoc: addTime,
packets: addPackets,
size: addSize,
timeRem: -1,
events: -1,
},
extendErasureIntervals: {
time: eraseTime,
timeLoc: eraseTime,
packets: erasePackets,
size: eraseSize,
timeRem: -1,
events: -1,
},
synchronisation: {
time: syncTime,
timeLoc: syncTime,
packets: syncPackets,
size: syncSize,
timeRem: -1,
events: -1,
},
})
......@@ -724,19 +866,25 @@ describe("drawing app mesh", () => {
timeout = setTimeout(() => {
printBenchmark("path draw and erase [parallel]", ITERATIONS, {
addPath: {
time: addTime,
timeLoc: addTime,
packets: addPackets,
size: addSize,
timeRem: -1,
events: -1,
},
extendErasureIntervals: {
time: eraseTime,
timeLoc: eraseTime,
packets: erasePackets,
size: eraseSize,
timeRem: -1,
events: -1,
},
synchronisation: {
time: syncTime,
timeLoc: syncTime,
packets: syncPackets,
size: syncSize,
timeRem: -1,
events: -1,
},
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment