mirror of
https://github.com/status-im/nim-eth.git
synced 2025-03-03 15:10:35 +00:00
Adjust uTP benchmarking tests to use multiple nodes (#772)
This commit is contained in:
parent
c640d3c444
commit
51f56b05b3
@ -234,9 +234,10 @@ procSuite "uTP over discovery v5 protocol":
|
||||
await node1.closeWait()
|
||||
await node2.closeWait()
|
||||
|
||||
asyncTest "Data transfer over multiple sockets":
|
||||
asyncTest "Data transfer over multiple sockets over multiple nodes":
|
||||
const
|
||||
amountOfTransfers = 25
|
||||
amountOfTransfers = 5
|
||||
amountOfNodes = 5
|
||||
dataToSend: seq[byte] = repeat(byte 0xA0, 1_000_000)
|
||||
|
||||
var readFutures: seq[Future[void]]
|
||||
@ -268,21 +269,26 @@ procSuite "uTP over discovery v5 protocol":
|
||||
noCancel fut
|
||||
|
||||
let
|
||||
address1 = localAddress(20302)
|
||||
address2 = localAddress(20303)
|
||||
node1 = initDiscoveryNode(
|
||||
rng, PrivateKey.random(rng[]), address1)
|
||||
node2 = initDiscoveryNode(
|
||||
rng, PrivateKey.random(rng[]), address2)
|
||||
sendingNode = initDiscoveryNode(
|
||||
rng, PrivateKey.random(rng[]), localAddress(20302))
|
||||
sendingUtpNode = UtpDiscv5Protocol.new(
|
||||
sendingNode, utpProtId, handleIncomingConnectionDummy)
|
||||
|
||||
utp1 = UtpDiscv5Protocol.new(
|
||||
node1, utpProtId, handleIncomingConnectionDummy)
|
||||
utp2 {.used.} = UtpDiscv5Protocol.new(
|
||||
node2, utpProtId, handleIncomingConnection)
|
||||
var nodeList: seq[discv5_protocol.Protocol]
|
||||
var utpNodeList: seq[UtpDiscv5Protocol]
|
||||
for i in 0..<amountOfNodes:
|
||||
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:
|
||||
(await node1.ping(node2.localNode)).isOk()
|
||||
(await sendingNode.ping(node.localNode)).isOk()
|
||||
|
||||
proc connectSendAndCheck(
|
||||
utpProto: UtpDiscv5Protocol,
|
||||
@ -301,22 +307,26 @@ procSuite "uTP over discovery v5 protocol":
|
||||
|
||||
let t0 = Moment.now()
|
||||
for i in 0..<amountOfTransfers:
|
||||
asyncSpawn utp1.connectSendAndCheck(
|
||||
NodeAddress.init(node2.localNode.id, address2))
|
||||
for j in 0..<amountOfNodes:
|
||||
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 allFutures(readFutures)
|
||||
let elapsed = Moment.now() - t0
|
||||
|
||||
await utp1.shutdownWait()
|
||||
await utp2.shutdownWait()
|
||||
await sendingUtpNode.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 throughput = megabitsSent / seconds
|
||||
|
||||
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"
|
||||
|
@ -551,9 +551,10 @@ procSuite "uTP over UDP protocol":
|
||||
|
||||
await s.close()
|
||||
|
||||
asyncTest "Data transfer over multiple sockets":
|
||||
asyncTest "Data transfer over multiple sockets over multiple nodes":
|
||||
const
|
||||
amountOfTransfers = 100
|
||||
amountOfTransfers = 20
|
||||
amountOfNodes = 5
|
||||
dataToSend: seq[byte] = repeat(byte 0xA0, 1_000_000)
|
||||
|
||||
var readFutures: seq[Future[void]]
|
||||
@ -585,10 +586,16 @@ procSuite "uTP over UDP protocol":
|
||||
noCancel fut
|
||||
|
||||
let
|
||||
address1 = initTAddress("127.0.0.1", 9079)
|
||||
utpProto1 = UtpProtocol.new(handleIncomingConnectionDummy, address1)
|
||||
address2 = initTAddress("127.0.0.1", 9080)
|
||||
utpProto2 = UtpProtocol.new(handleIncomingConnection, address2)
|
||||
address = initTAddress("127.0.0.1", 9079)
|
||||
utpNode = UtpProtocol.new(handleIncomingConnectionDummy, address)
|
||||
|
||||
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(
|
||||
utpProto: UtpProtocol,
|
||||
@ -607,21 +614,23 @@ procSuite "uTP over UDP protocol":
|
||||
|
||||
let t0 = Moment.now()
|
||||
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 allFutures(readFutures)
|
||||
let elapsed = Moment.now() - t0
|
||||
|
||||
await utpProto1.shutdownWait()
|
||||
await utpProto2.shutdownWait()
|
||||
await utpNode.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 throughput = megabitsSent / seconds
|
||||
|
||||
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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user