diff --git a/perf/impl/Makefile b/perf/impl/Makefile index c4d4f7e01..526c1a16f 100644 --- a/perf/impl/Makefile +++ b/perf/impl/Makefile @@ -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 $@ @@ -18,6 +19,9 @@ $(HTTPS_SUBDIRS): $(QUIC_GO_SUBDIRS): $(MAKE) -C $@ +$(NIM_SUBDIRS): + $(MAKE) -C $@ + $(JS_SUBDIRS): $(MAKE) -C $@ @@ -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 diff --git a/perf/impl/nim-libp2p/v0.1/.gitignore b/perf/impl/nim-libp2p/v0.1/.gitignore new file mode 100644 index 000000000..357758b67 --- /dev/null +++ b/perf/impl/nim-libp2p/v0.1/.gitignore @@ -0,0 +1,8 @@ +nimble.develop +nimble.paths + + +nimlibp2p +nim-libp2p +nim-libp2p-* +nim-libp2p-*.zip \ No newline at end of file diff --git a/perf/impl/nim-libp2p/v0.1/Makefile b/perf/impl/nim-libp2p/v0.1/Makefile new file mode 100644 index 000000000..351ba3922 --- /dev/null +++ b/perf/impl/nim-libp2p/v0.1/Makefile @@ -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 \ No newline at end of file diff --git a/perf/impl/nim-libp2p/v0.1/config.nims b/perf/impl/nim-libp2p/v0.1/config.nims new file mode 100644 index 000000000..8ee48d258 --- /dev/null +++ b/perf/impl/nim-libp2p/v0.1/config.nims @@ -0,0 +1,4 @@ +# begin Nimble config (version 2) +when withDir(thisDir(), system.fileExists("nimble.paths")): + include "nimble.paths" +# end Nimble config diff --git a/perf/impl/nim-libp2p/v0.1/perf b/perf/impl/nim-libp2p/v0.1/perf new file mode 100755 index 000000000..a681c96b1 Binary files /dev/null and b/perf/impl/nim-libp2p/v0.1/perf differ diff --git a/perf/impl/nim-libp2p/v0.1/perf.nim b/perf/impl/nim-libp2p/v0.1/perf.nim new file mode 100644 index 000000000..4b232aeaa --- /dev/null +++ b/perf/impl/nim-libp2p/v0.1/perf.nim @@ -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()) diff --git a/perf/impl/nim-libp2p/v0.1/pref.nimble b/perf/impl/nim-libp2p/v0.1/pref.nimble new file mode 100644 index 000000000..708964761 --- /dev/null +++ b/perf/impl/nim-libp2p/v0.1/pref.nimble @@ -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" diff --git a/perf/runner/versionsInput.json b/perf/runner/versionsInput.json index 363e491f0..21fd7e976 100644 --- a/perf/runner/versionsInput.json +++ b/perf/runner/versionsInput.json @@ -29,6 +29,13 @@ "quic-v1" ] }, + { + "id": "v1.1", + "implementation": "nim-libp2p", + "transportStacks": [ + "tcp" + ] + }, { "id": "v2.8", "implementation": "js-libp2p",