-
Notifications
You must be signed in to change notification settings - Fork 43
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
lchenut
wants to merge
12
commits into
libp2p:master
Choose a base branch
from
lchenut:perf-nim
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b049b3d
Added nim perf implementation
lchenut e0fa824
fix arg parser
lchenut f8d26bf
clean the makefile
lchenut fe07117
perf: update benchmark results
mxinden 0578c83
add makefile & version.ts informations
lchenut 757ec30
update .PHONY
lchenut 922a2fe
Fix version.ts
lchenut 2758f09
Merge remote-tracking branch 'origin/master' into perf-nim
lchenut 7b1f409
Merge branch 'master' into perf-nim
mxinden 5cfd56d
fix(perf): nim-libp2p - remove the docker's user option
lchenut 473e013
Merge remote-tracking branch 'origin/perf-nim' into perf-nim
lchenut b16f05d
Rename directory to match the nim-libp2p version
lchenut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI has failed:
Is this actually producing a binary under the name
perf
?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
/lib64/ld-linux-x86-64.so.2 isn't found
And I have no idea what I should use instead.