Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e6e38b9
add pref nim libp2p
vladopajic Jun 5, 2025
12ce98e
fixed flags parsing
vladopajic Jun 6, 2025
7b478e7
fix
vladopajic Jun 6, 2025
a6f2281
perf dependencies reduced to min
vladopajic Jun 6, 2025
674129e
add pref nim libp2p
vladopajic Jun 5, 2025
6378807
fixed flags parsing
vladopajic Jun 6, 2025
411198f
fix
vladopajic Jun 6, 2025
4b14d12
perf dependencies reduced to min
vladopajic Jun 6, 2025
29f41fe
mv perf executable
p-shahi Jun 6, 2025
d0144bb
fix args parsing
vladopajic Jun 6, 2025
25fbf7f
rm v0.1
vladopajic Jun 6, 2025
d70fc5c
fix arg variable in log
vladopajic Jun 6, 2025
569f3aa
use duration from perf client
vladopajic Jun 6, 2025
84331ef
Merge branch 'add-perf-nim-libp2p' into add-pref-nim-libp2p
p-shahi Jun 6, 2025
d7adb8b
add nim-libp2p to runner test-filter
p-shahi Jun 6, 2025
6a593c0
fix Makefile
p-shahi Jun 6, 2025
53607c4
Merge branch 'add-perf-nim-libp2p' into add-pref-nim-libp2p
vladopajic Jun 9, 2025
390297e
rm perf
vladopajic Jun 9, 2025
249e368
improve build
vladopajic Jun 9, 2025
2c4df9d
Merge branch 'add-pref-nim-libp2p' of github.com:vladopajic/test-plan…
vladopajic Jun 9, 2025
81b7403
add intermediateReport and yamux
vladopajic Jun 9, 2025
485ad5a
various improvements perf
vladopajic Jun 11, 2025
2e95f97
bump nim-libp2p lib
vladopajic Jun 13, 2025
d07a854
silent compile
vladopajic Jun 24, 2025
a1ea931
use yamux
vladopajic Jun 24, 2025
efd847a
intermediary stats report as diff from previous
vladopajic Jun 24, 2025
36c539f
various smaller improvements
vladopajic Jun 25, 2025
b60ceaa
cosmetics
vladopajic Jun 25, 2025
9b8c59d
update compile time flags
vladopajic Jul 1, 2025
49e2a4c
nim c flags update
vladopajic Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions perf/impl/nim-libp2p/v1.10/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# nim project
nimble.develop
nimble.paths


nimlibp2p
nim-libp2p
nim-libp2p-*
nim-libp2p-*.zip
# the binary output
perf
33 changes: 9 additions & 24 deletions perf/impl/nim-libp2p/v1.10/Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
# commit corresponds to v1.10.2 (draft) version of nim-libp2p
commitSha := 3a7745f920d11fb29305070cd9991874529dfc28

all: perf

perf: perf.nim nim-libp2p
# `nim c` command uses flags to:
# - minimize output while compile - to reduce log output in the ci that runs perf benchmarking
# - optimize for speed - to have the best possible performance

perf: perf.nim
docker run --rm \
-v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp nimlang/nim:2.2.0 \
sh -c ' \
rm -f nimlibp2p && \
ln -s nim-libp2p nimlibp2p && \
cd nim-libp2p && \
nimble install_pinned && cd ../ && \
nimble install -y --depsOnly && \
nim c --threads:off --NimblePath:nim-libp2p/nimbledeps/pkgs -p:nim-libp2p -d:chronicles_log_level=WARN -d:release perf.nim && \
chown -R $(shell id -u):$(shell id -g) .'

nim-libp2p: nim-libp2p-${commitSha}
rm -rf nim-libp2p
ln -s nim-libp2p-${commitSha} nim-libp2p

nim-libp2p-${commitSha}: nim-libp2p-${commitSha}.zip
unzip -o nim-libp2p-${commitSha}.zip

nim-libp2p-${commitSha}.zip:
wget -O $@ "https://github.com/status-im/nim-libp2p/archive/${commitSha}.zip"
nimble install -y --depsOnly && \
nim c --hints:off --verbosity:0 --warning[all]:off --threads:off --NimblePath:nim-libp2p/nimbledeps/pkgs -p:nim-libp2p -d:chronicles_enabled=off -d:release -d:danger -d:lto --opt:speed --stacktrace:off perf.nim && \
chown -R $(shell id -u):$(shell id -g) .'

clean:
rm -rf nim-libp2p
rm -rf nim-libp2p-${commitSha}
rm -rf nim-libp2p-${commitSha}.zip
rm -f perf

.PHONY: all clean
97 changes: 61 additions & 36 deletions perf/impl/nim-libp2p/v1.10/perf.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os, strutils, strformat, json
import chronos, bearssl/[rand, hash]
import ./nimlibp2p/libp2p
import
./nimlibp2p/libp2p/[protocols/perf/client, protocols/perf/server, protocols/perf/core]
import libp2p
import libp2p/[protocols/perf/client, protocols/perf/server, protocols/perf/core]

const fixedPeerId = "12D3KooWPnQpbXGqzgESFrkaFh1xvCrB64ADnLQQRYfMhnbSuFHF"

Expand Down Expand Up @@ -34,63 +33,89 @@ proc initFlagsFromParams(flags: var Flags) =
flags.downloadBytes = parseUInt(paramStr(i))
else:
stderr.writeLine("unsupported flag: " & paramStr(i))

if flags.serverIpAddress == TransportAddress():
raise newException(ValueError, "server-address is not set")


proc seededRng(): ref HmacDrbgContext =
var seed: cint = 0
var rng = (ref HmacDrbgContext)()
hmacDrbgInit(rng[], addr sha256Vtable, cast[pointer](addr seed), sizeof(seed).uint)
return rng

proc runServer(f: Flags) {.async.} =
let endlessFut = newFuture[void]()
var switch = SwitchBuilder
proc makeSwitch(f: Flags): Switch =
let addrs =
if f.runServer:
@[MultiAddress.init(f.serverIpAddress).tryGet()]
else:
@[MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet()]

let rng =
if f.runServer:
seededRng() # use fixed seed that will match fixedPeerId
else:
newRng()

return SwitchBuilder
.new()
.withRng(seededRng())
.withAddresses(@[MultiAddress.init(f.serverIpAddress).tryGet()])
.withRng(rng)
.withAddresses(addrs)
.withTcpTransport()
# .withQuicTransport()
.withMplex()
.withYamux()
.withNoise()
.build()

proc runServer(f: Flags) {.async.} =
var switch = makeSwitch(f)
switch.mount(Perf.new())
await switch.start()
await endlessFut # Await forever, exit on interrupt

await newFuture[void]() # await forever, exit on interrupt

proc writeReport(p: PerfClient, done: Future[void]) {.async.} =
proc writeStats(stats: Stats) =
let result =
%*{
"type": if stats.isFinal: "final" else: "intermediary",
"timeSeconds": stats.duration.nanoseconds.float / 1_000_000_000.0,
"uploadBytes": stats.uploadBytes,
"downloadBytes": stats.downloadBytes,
}
stdout.writeLine($result)

var prevStats: Stats
while true:
await sleepAsync(1000.milliseconds)
var stats = p.currentStats()
if stats.isFinal:
writeStats(stats)
done.complete()
return

# intermediary stats report should be diff from last intermediary report
let statsInitial = stats
stats.duration -= prevStats.duration
stats.uploadBytes -= prevStats.uploadBytes
stats.downloadBytes -= prevStats.downloadBytes
prevStats = statsInitial

writeStats(stats)

proc runClient(f: Flags) {.async.} =
let switchBuilder = SwitchBuilder
.new()
.withRng(newRng())
.withAddress(MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet())
.withMplex()
.withNoise()
let switch =
case f.transport
of "tcp":
switchBuilder.withTcpTransport().build()
# of "quic-v1": switchBuilder.withQuicTransport().build()
else:
raise newException(ValueError, "unsupported transport: " & f.transport)
let switch = makeSwitch(f)
await switch.start()

let conn = await switch.dial(
PeerId.init(fixedPeerId).tryGet(),
@[MultiAddress.init(f.serverIpAddress).tryGet()],
PerfCodec,
)
let dur = await PerfClient.perf(conn, f.uploadBytes, f.downloadBytes)

let resultFinal =
%*{
"type": "final",
"timeSeconds": dur.seconds,
"uploadBytes": f.uploadBytes,
"downloadBytes": f.downloadBytes,
}
echo $resultFinal
var perfClient = PerfClient.new()
var done = newFuture[void]("report done")
discard perfClient.perf(conn, f.uploadBytes, f.downloadBytes)
asyncSpawn writeReport(perfClient, done)

await done # block until reporting finishes

proc main() {.async.} =
var flags = Flags()
Expand Down
6 changes: 4 additions & 2 deletions perf/impl/nim-libp2p/v1.10/pref.nimble
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mode = ScriptMode.Verbose

packageName = "nim-libp2p pref"
packageName = "pref"
version = "1.10"
author = "Status Research & Development GmbH"
description = "LibP2P implementation"
description = "nim perf implementation"
license = "MIT"

requires "nim >= 2.2.0", "chronos >= 4.0.4", "bearssl >= 0.2.5"
# commit corresponds to v1.10.X (master branch) version of nim-libp2p
requires "libp2p#be1a2023ce41a4ccd298215f614820a8f3f0eb6e"