Skip to content
Draft
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
30 changes: 3 additions & 27 deletions perf/impl/Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
GO_SUBDIRS := $(wildcard go-libp2p/*/.)
RUST_SUBDIRS := $(wildcard rust-libp2p/*/.)
HTTPS_SUBDIRS := $(wildcard https/*/.)
QUIC_GO_SUBDIRS := $(wildcard quic-go/*/.)
JS_SUBDIRS := $(wildcard js-libp2p/*/.)

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

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

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

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

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

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

go-libp2p: $(GO_SUBDIRS)

rust-libp2p: $(RUST_SUBDIRS)

https: $(HTTPS_SUBDIRS)

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: $(JS_SUBDIRS:%=%clean)

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

.PHONY: $(RUST_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS) $(JS_SUBDIRS) all clean
.PHONY: $(JS_SUBDIRS) all clean
15 changes: 15 additions & 0 deletions perf/impl/js-libp2p/v2.8-eventtarget/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DOCKER_IMAGE := node:22-alpine
DOCKER_RUN := docker run --rm -v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp $(DOCKER_IMAGE)
DOCKER_RUN_LIBP2P := docker run --rm -v "$(shell pwd)/libp2p":/usr/src/myapp/libp2p -w /usr/src/myapp/libp2p $(DOCKER_IMAGE)

all: perf

perf:
$(DOCKER_RUN_LIBP2P) npm ci
$(DOCKER_RUN_LIBP2P) npm run build
$(DOCKER_RUN) npm ci

clean:
rm -rf node_modules

.PHONY: all clean perf
11 changes: 11 additions & 0 deletions perf/impl/js-libp2p/v2.8-eventtarget/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Server:

```
./perf --run-server --server-address 127.0.0.1:1234 --transport tcp
```

Client

```
./perf --server-address 127.0.0.1:1234 --transport tcp --upload-bytes 10000000 --download bytes=10000000
```
105 changes: 105 additions & 0 deletions perf/impl/js-libp2p/v2.8-eventtarget/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { parseArgs } from 'node:util'
import { noise } from './libp2p/packages/connection-encrypter-noise/dist/src/index.js'
import { yamux } from './libp2p/packages/stream-multiplexer-yamux/dist/src/index.js'
import { perf } from './libp2p/packages/protocol-perf/dist/src/index.js'
import { tcp } from './libp2p/packages/transport-tcp/dist/src/index.js'
import { multiaddr } from '@multiformats/multiaddr'
import { createLibp2p } from './libp2p/packages/libp2p/dist/src/index.js'

const argv = parseArgs({
options: {
'run-server': {
type: 'string',
default: 'false'
},
'server-address': {
type: 'string'
},
transport: {
type: 'string',
default: 'tcp'
},
'upload-bytes': {
type: 'string',
default: '0'
},
'download-bytes': {
type: 'string',
default: '0'
}
}
})

/**
* @param {boolean} runServer
* @param {string} serverAddress
* @param {string} transport
* @param {number} uploadBytes
* @param {number} downloadBytes
*/
export async function main (runServer, serverAddress, transport, uploadBytes, downloadBytes) {
const { host, port } = splitHostPort(serverAddress)

const config = {
transports: [
tcp()
],
streamMuxers: [
yamux()
],
connectionEncrypters: [
noise()
],
services: {
perf: perf()
}
}

if (runServer) {
Object.assign(config, {
addresses: {
listen: [
// #TODO: right now we only support tcp
`/ip4/${host}/tcp/${port}`
]
}
})
}

const node = await createLibp2p(config)

await node.start()

if (!runServer) {
for await (const output of node.services.perf.measurePerformance(multiaddr(`/ip4/${host}/tcp/${port}`), uploadBytes, downloadBytes)) {
// eslint-disable-next-line no-console
console.log(JSON.stringify(output))
}

await node.stop()
}
}

/**
* @param {string} address
* @returns { host: string, port?: string }
*/
function splitHostPort (address) {
try {
const parts = address.split(':')
const host = parts[0]
const port = parts[1]
return {
host,
port
}
} catch (error) {
throw Error('Invalid server address')
}
}

main(argv.values['run-server'] === 'true', argv.values['server-address'], argv.values.transport, Number(argv.values['upload-bytes']), Number(argv.values['download-bytes'])).catch((err) => {
// eslint-disable-next-line no-console
console.error(err)
process.exit(1)
})
Loading