Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions perf/impl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ GO_SUBDIRS := $(wildcard go-libp2p/*/.)
RUST_SUBDIRS := $(wildcard rust-libp2p/*/.)
HTTPS_SUBDIRS := $(wildcard https/*/.)
QUIC_GO_SUBDIRS := $(wildcard quic-go/*/.)
NIM_SUBDIRS := $(wildcard nim-libp2p/*/.)
JS_SUBDIRS := $(wildcard js-libp2p/*/.)

all: $(RUST_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS) $(JS_SUBDIRS)
all: $(RUST_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS) $(NIM_SUBDIRS) $(JS_SUBDIRS)

$(RUST_SUBDIRS):
$(MAKE) -C $@
Expand All @@ -18,6 +19,9 @@ $(HTTPS_SUBDIRS):
$(QUIC_GO_SUBDIRS):
$(MAKE) -C $@

$(NIM_SUBDIRS):
$(MAKE) -C $@

$(JS_SUBDIRS):
$(MAKE) -C $@

Expand All @@ -31,9 +35,9 @@ quic-go: $(QUIC_GO_SUBDIRS)

js-libp2p: $(JS_SUBDIRS)

clean: $(RUST_SUBDIRS:%=%clean) $(GO_SUBDIRS:%=%clean) $(HTTPS_SUBDIRS:%=%clean) $(QUIC_GO_SUBDIRS:%=%clean) $(JS_SUBDIRS:%=%clean)
clean: $(RUST_SUBDIRS:%=%clean) $(GO_SUBDIRS:%=%clean) $(HTTPS_SUBDIRS:%=%clean) $(QUIC_GO_SUBDIRS:%=%clean) $(NIM_SUBDIRS:%=%clean) $(JS_SUBDIRS:%=%clean)

%clean:
$(MAKE) -C $* clean

.PHONY: $(RUST_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS) $(JS_SUBDIRS) all clean
.PHONY: $(RUST_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS) $(NIM_SUBDIRS) $(JS_SUBDIRS) all clean
8 changes: 8 additions & 0 deletions perf/impl/nim-libp2p/v0.1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
nimble.develop
nimble.paths


nimlibp2p
nim-libp2p
nim-libp2p-*
nim-libp2p-*.zip
33 changes: 33 additions & 0 deletions perf/impl/nim-libp2p/v0.1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# commit corresponds to v1.10.1 version of nim-libp2p
commitSha := cd60b254a0700b0daac7a6cb2c0c48860b57c539

all: perf

perf: perf.nim nim-libp2p
docker run --rm \
-v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp nimlang/nim:2.2.0 \
sh -c ' \
rm 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"

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

.PHONY: all clean
4 changes: 4 additions & 0 deletions perf/impl/nim-libp2p/v0.1/config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# begin Nimble config (version 2)
when withDir(thisDir(), system.fileExists("nimble.paths")):
include "nimble.paths"
# end Nimble config
Binary file added perf/impl/nim-libp2p/v0.1/perf
Binary file not shown.
102 changes: 102 additions & 0 deletions perf/impl/nim-libp2p/v0.1/perf.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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]

const fixedPeerId = "12D3KooWPnQpbXGqzgESFrkaFh1xvCrB64ADnLQQRYfMhnbSuFHF"

type Flags = object
runServer: bool
serverIpAddress: TransportAddress
transport: string
uploadBytes: uint
downloadBytes: uint

proc initFlagsFromParams(flags: var Flags) =
var i = 1
while i < paramCount():
case paramStr(i)
of "--run-server":
flags.runServer = true
of "--server-ip-address":
flags.serverIpAddress = initTAddress(paramStr(i + 1))
i += 1
of "--transport":
flags.transport = paramStr(i + 1)
i += 1
of "--upload-bytes":
flags.uploadBytes = parseUInt(paramStr(i + 1))
i += 1
of "--download-bytes":
flags.downloadBytes = parseUInt(paramStr(i + 1))
i += 1
else:
discard
i += 1

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
.new()
.withRng(seededRng())
.withAddresses(@[MultiAddress.init(f.serverIpAddress).tryGet()])
.withTcpTransport()
# .withQuicTransport()
.withMplex()
.withNoise()
.build()
switch.mount(Perf.new())
await switch.start()
await endlessFut # Await forever, exit on interrupt

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 (ref Defect)()
await switch.start()

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

let dur = Moment.now() - startTime
let resultFinal =
%*{
"type": "final",
"timeSeconds": dur.seconds,
"uploadBytes": f.uploadBytes,
"downloadBytes": f.downloadBytes,
}
echo $resultFinal

proc main() {.async.} =
var flags = Flags()
flags.initFlagsFromParams()

if flags.runServer:
await runServer(flags)
else:
await runClient(flags)

waitFor(main())
12 changes: 12 additions & 0 deletions perf/impl/nim-libp2p/v0.1/pref.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mode = ScriptMode.Verbose

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

requires "nim >= 2.2.0",
"nimcrypto >= 0.6.0 & < 0.7.0", "dnsclient >= 0.3.0 & < 0.4.0", "bearssl >= 0.2.5",
"chronicles >= 0.10.3 & < 0.11.0", "chronos >= 4.0.4", "metrics", "secp256k1",
"stew >= 0.4.0", "websock >= 0.2.0", "unittest2", "results", "quic >= 0.2.7"
7 changes: 7 additions & 0 deletions perf/runner/versionsInput.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
"quic-v1"
]
},
{
"id": "v1.1",
"implementation": "nim-libp2p",
"transportStacks": [
"tcp"
]
},
{
"id": "v2.8",
"implementation": "js-libp2p",
Expand Down