Adjust uTP benchmarking tests to use multiple nodes (#772)

This commit is contained in:
kdeme 2025-02-07 10:49:08 +01:00 committed by GitHub
parent c640d3c444
commit 51f56b05b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 34 deletions

View File

@ -234,9 +234,10 @@ procSuite "uTP over discovery v5 protocol":
await node1.closeWait() await node1.closeWait()
await node2.closeWait() await node2.closeWait()
asyncTest "Data transfer over multiple sockets": asyncTest "Data transfer over multiple sockets over multiple nodes":
const const
amountOfTransfers = 25 amountOfTransfers = 5
amountOfNodes = 5
dataToSend: seq[byte] = repeat(byte 0xA0, 1_000_000) dataToSend: seq[byte] = repeat(byte 0xA0, 1_000_000)
var readFutures: seq[Future[void]] var readFutures: seq[Future[void]]
@ -268,21 +269,26 @@ procSuite "uTP over discovery v5 protocol":
noCancel fut noCancel fut
let let
address1 = localAddress(20302) sendingNode = initDiscoveryNode(
address2 = localAddress(20303) rng, PrivateKey.random(rng[]), localAddress(20302))
node1 = initDiscoveryNode( sendingUtpNode = UtpDiscv5Protocol.new(
rng, PrivateKey.random(rng[]), address1) sendingNode, utpProtId, handleIncomingConnectionDummy)
node2 = initDiscoveryNode(
rng, PrivateKey.random(rng[]), address2)
utp1 = UtpDiscv5Protocol.new( var nodeList: seq[discv5_protocol.Protocol]
node1, utpProtId, handleIncomingConnectionDummy) var utpNodeList: seq[UtpDiscv5Protocol]
utp2 {.used.} = UtpDiscv5Protocol.new( for i in 0..<amountOfNodes:
node2, utpProtId, handleIncomingConnection) let
node = initDiscoveryNode(
rng, PrivateKey.random(rng[]), localAddress(20303 + i))
utpNode = UtpDiscv5Protocol.new(
node, utpProtId, handleIncomingConnection)
# nodes must have session between each other nodeList.add(node)
utpNodeList.add(utpNode)
# nodes must have discv5 session between each other
check: check:
(await node1.ping(node2.localNode)).isOk() (await sendingNode.ping(node.localNode)).isOk()
proc connectSendAndCheck( proc connectSendAndCheck(
utpProto: UtpDiscv5Protocol, utpProto: UtpDiscv5Protocol,
@ -301,22 +307,26 @@ procSuite "uTP over discovery v5 protocol":
let t0 = Moment.now() let t0 = Moment.now()
for i in 0..<amountOfTransfers: for i in 0..<amountOfTransfers:
asyncSpawn utp1.connectSendAndCheck( for j in 0..<amountOfNodes:
NodeAddress.init(node2.localNode.id, address2)) asyncSpawn sendingUtpNode.connectSendAndCheck(
NodeAddress.init(nodeList[j].localNode.id, nodeList[j].localNode.address.value()))
while readFutures.len() < amountOfTransfers: while readFutures.len() < amountOfTransfers * amountOfNodes:
await sleepAsync(milliseconds(100)) await sleepAsync(milliseconds(100))
await allFutures(readFutures) await allFutures(readFutures)
let elapsed = Moment.now() - t0 let elapsed = Moment.now() - t0
await utp1.shutdownWait() await sendingUtpNode.shutdownWait()
await utp2.shutdownWait() await sendingNode.closeWait()
for i in 0..<amountOfNodes:
await utpNodeList[i].shutdownWait()
await nodeList[i].closeWait()
let megabitsSent = amountOfTransfers * dataToSend.len() * 8 / 1_000_000 let megabitsSent = amountOfTransfers * amountOfNodes * dataToSend.len() * 8 / 1_000_000
let seconds = float(elapsed.nanoseconds) / 1_000_000_000 let seconds = float(elapsed.nanoseconds) / 1_000_000_000
let throughput = megabitsSent / seconds let throughput = megabitsSent / seconds
echo "" echo ""
echo "Sent ", amountOfTransfers, " asynchronous uTP transfers in ", seconds, echo "Sent ", amountOfTransfers, " asynchronous uTP transfers to ", amountOfNodes, " nodes in ", seconds,
" seconds, payload throughput: ", throughput, " Mbit/s" " seconds, payload throughput: ", throughput, " Mbit/s"

View File

@ -551,9 +551,10 @@ procSuite "uTP over UDP protocol":
await s.close() await s.close()
asyncTest "Data transfer over multiple sockets": asyncTest "Data transfer over multiple sockets over multiple nodes":
const const
amountOfTransfers = 100 amountOfTransfers = 20
amountOfNodes = 5
dataToSend: seq[byte] = repeat(byte 0xA0, 1_000_000) dataToSend: seq[byte] = repeat(byte 0xA0, 1_000_000)
var readFutures: seq[Future[void]] var readFutures: seq[Future[void]]
@ -585,10 +586,16 @@ procSuite "uTP over UDP protocol":
noCancel fut noCancel fut
let let
address1 = initTAddress("127.0.0.1", 9079) address = initTAddress("127.0.0.1", 9079)
utpProto1 = UtpProtocol.new(handleIncomingConnectionDummy, address1) utpNode = UtpProtocol.new(handleIncomingConnectionDummy, address)
address2 = initTAddress("127.0.0.1", 9080)
utpProto2 = UtpProtocol.new(handleIncomingConnection, address2) var utpNodeList: seq[UtpProtocol]
for i in 0..<amountOfNodes:
let
address = initTAddress("127.0.0.1", 9080 + i)
utpNode = UtpProtocol.new(handleIncomingConnection, address)
utpNodeList.add(utpNode)
proc connectSendAndCheck( proc connectSendAndCheck(
utpProto: UtpProtocol, utpProto: UtpProtocol,
@ -607,21 +614,23 @@ procSuite "uTP over UDP protocol":
let t0 = Moment.now() let t0 = Moment.now()
for i in 0..<amountOfTransfers: for i in 0..<amountOfTransfers:
asyncSpawn utpProto1.connectSendAndCheck(address2) for j in 0..<amountOfNodes:
asyncSpawn utpNode.connectSendAndCheck(initTAddress("127.0.0.1", 9080 + j))
while readFutures.len() < amountOfTransfers: while readFutures.len() < amountOfTransfers * amountOfNodes:
await sleepAsync(milliseconds(100)) await sleepAsync(milliseconds(100))
await allFutures(readFutures) await allFutures(readFutures)
let elapsed = Moment.now() - t0 let elapsed = Moment.now() - t0
await utpProto1.shutdownWait() await utpNode.shutdownWait()
await utpProto2.shutdownWait() for i in 0..<amountOfNodes:
await utpNodeList[i].shutdownWait()
let megabitsSent = amountOfTransfers * dataToSend.len() * 8 / 1_000_000 let megabitsSent = amountOfTransfers * amountOfNodes * dataToSend.len() * 8 / 1_000_000
let seconds = float(elapsed.nanoseconds) / 1_000_000_000 let seconds = float(elapsed.nanoseconds) / 1_000_000_000
let throughput = megabitsSent / seconds let throughput = megabitsSent / seconds
echo "" echo ""
echo "Sent ", amountOfTransfers, " asynchronous uTP transfers in ", seconds, echo "Sent ", amountOfTransfers, " asynchronous uTP transfers to ", amountOfNodes, " nodes in ", seconds,
" seconds, payload throughput: ", throughput, " Mbit/s" " seconds, payload throughput: ", throughput, " Mbit/s"