Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(perf): add nim-libp2p v1.1 #262

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
7 changes: 5 additions & 2 deletions perf/impl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ RUST_SUBDIRS := $(wildcard rust-libp2p/*/.)
RUST_QUINN_SUBDIRS := $(wildcard rust-libp2p-quinn/*/.)
HTTPS_SUBDIRS := $(wildcard https/*/.)
QUIC_GO_SUBDIRS := $(wildcard quic-go/*/.)
NIM_SUBDIRS := $(wildcard nim-libp2p/*/.)

all: $(RUST_SUBDIRS) $(RUST_QUINN_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS)
$(RUST_SUBDIRS):
Expand All @@ -15,10 +16,12 @@ $(HTTPS_SUBDIRS):
$(MAKE) -C $@
$(QUIC_GO_SUBDIRS):
$(MAKE) -C $@
$(NIM_SUBDIRS):
$(MAKE) -C $@

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

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

.PHONY: $(RUST_SUBDIRS) $(RUST_QUINN_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS) all clean
.PHONY: $(RUST_SUBDIRS) $(RUST_QUINN_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS) $(QUIC_GO_SUBDIRS) $(NIM_SUBDIRS) all clean
23 changes: 23 additions & 0 deletions perf/impl/nim-libp2p/v1.0/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
commitSha := e03547ea3e2f0372c540c586e993803299d3c4b6

all: perf

perf: perf.nim nim-libp2p
docker run --rm --user "$(shell id -u):$(shell id -g)" -v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp nimlang/nim:1.6.10 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI has failed:

bash: line 1: ./impl/nim-libp2p/v1.0/perf: No such file or directory

Is this actually producing a binary under the name perf?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I was afraid of. It's a Docker problem, it creates an ELF executable, no matter what, where it should create a host-compatible executable.

But it seems that there's no nim image on docker hub with this option.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a bit of research, the problem doesn't come from the executable itself, but come from the linking of the .so...

$ file perf
perf: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=895de8bd9fdf766ac9448fa05056cb4370bb6f54, for GNU/Linux 3.2.0, not stripped

/lib64/ld-linux-x86-64.so.2 isn't found

And I have no idea what I should use instead.


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
87 changes: 87 additions & 0 deletions perf/impl/nim-libp2p/v1.0/perf.nim
Original file line number Diff line number Diff line change
@@ -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())
Loading