diff --git a/perf/impl/Makefile b/perf/impl/Makefile index e274d58dc..6e72dcc9b 100644 --- a/perf/impl/Makefile +++ b/perf/impl/Makefile @@ -2,9 +2,11 @@ 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 $@ $(GO_SUBDIRS): @@ -13,12 +15,14 @@ $(HTTPS_SUBDIRS): $(MAKE) -C $@ $(QUIC_GO_SUBDIRS): $(MAKE) -C $@ +$(NIM_SUBDIRS): + $(MAKE) -C $@ $(JS_SUBDIRS): $(MAKE) -C $@ -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/v1.1/Makefile b/perf/impl/nim-libp2p/v1.1/Makefile new file mode 100644 index 000000000..1d79dcd72 --- /dev/null +++ b/perf/impl/nim-libp2p/v1.1/Makefile @@ -0,0 +1,29 @@ +commitSha := 61929aed6c49b4753dbb8414b9c3ed572b4a2abc + +all: perf + +perf: perf.nim nim-libp2p + docker run --rm \ + -v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp nimlang/nim:1.6.14 \ + sh -c ' \ + cd nim-libp2p && \ + nimble install_pinned && cd ../ && \ + nim c --NimblePath:nim-libp2p/nimbledeps/pkgs -p:nim-libp2p -d:chronicles_log_level=WARN --threads:off -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 -f perf + rm -f nim-libp2p + rm -rf nim-libp2p-* + +.PHONY: all clean diff --git a/perf/impl/nim-libp2p/v1.1/perf.nim b/perf/impl/nim-libp2p/v1.1/perf.nim new file mode 100644 index 000000000..e2a62e46d --- /dev/null +++ b/perf/impl/nim-libp2p/v1.1/perf.nim @@ -0,0 +1,87 @@ +import os, strutils, strformat +import chronos, bearssl/rand, bearssl/hash +import ./nim-libp2p/libp2p, + ./nim-libp2p/libp2p/protocols/perf/client, + ./nim-libp2p/libp2p/protocols/perf/server, + ./nim-libp2p/libp2p/protocols/perf/core + +const fixedPeerId = "12D3KooWPnQpbXGqzgESFrkaFh1xvCrB64ADnLQQRYfMhnbSuFHF" + +type + Flags = object + runServer: bool + serverIpAddress: TransportAddress + transport: string + uploadBytes: uint + downloadBytes: uint + +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(address: TransportAddress) {.async.} = + let endlessFut = newFuture[void]() + var switch = SwitchBuilder.new() + .withRng(seededRng()) + .withAddresses(@[ MultiAddress.init(address).tryGet() ]) + .withTcpTransport() + # .withQuicTransport() TODO: Remove comment when quic transport is done + .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() + # TODO: Remove comment when quic transport is done + # of "quic": switchBuilder.withQuicTransport().build() + else: raise (ref Defect)() + await switch.start() + let start = Moment.now() + let conn = await switch.dial(PeerId.init(fixedPeerId).tryGet(), + @[ MultiAddress.init(f.serverIpAddress).tryGet() ], + PerfCodec) + var dur = Moment.now() - start + dur = dur + (await PerfClient.perf(conn, f.uploadBytes, f.downloadBytes)) + let ns = dur.nanos + let s = Second.nanos + echo "{\"latency\": ", fmt"{ns div s}.{ns mod s:09}", "}" + +proc main() {.async.} = + var i = 1 + var flags = Flags(transport: "tcp") + 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 + + if flags.runServer: + await runServer(flags.serverIpAddress) + else: + await runClient(flags) + +waitFor(main()) diff --git a/perf/runner/benchmark-results.json b/perf/runner/benchmark-results.json index 5947c7318..fdec79bea 100644 --- a/perf/runner/benchmark-results.json +++ b/perf/runner/benchmark-results.json @@ -4394,4 +4394,4 @@ 4120000000 ] } -} \ No newline at end of file +} diff --git a/perf/runner/src/versions.ts b/perf/runner/src/versions.ts index 8f131df9f..d3725db8e 100644 --- a/perf/runner/src/versions.ts +++ b/perf/runner/src/versions.ts @@ -35,9 +35,14 @@ export const versions: Array = [ implementation: "go-libp2p", transportStacks: ["tcp", "quic-v1"] }, + { + id: "v1.1", + implementation: "nim-libp2p", + transportStacks: ["tcp"] + }, { id: "v0.46", implementation: "js-libp2p", transportStacks: ["tcp"] - } + }, ]