chore: add js-libp2p@v2.4.0 to perf
This commit is contained in:
parent
3b8de2d1d4
commit
12ff3b9ad6
|
@ -0,0 +1,12 @@
|
|||
DOCKER_IMAGE := node:20-alpine
|
||||
DOCKER_RUN := docker run --rm -v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp $(DOCKER_IMAGE)
|
||||
|
||||
all: perf
|
||||
|
||||
perf:
|
||||
$(DOCKER_RUN) npm ci
|
||||
|
||||
clean:
|
||||
rm -rf node_modules
|
||||
|
||||
.PHONY: all clean perf
|
|
@ -0,0 +1,108 @@
|
|||
import { noise } from '@chainsafe/libp2p-noise'
|
||||
import { yamux } from '@chainsafe/libp2p-yamux'
|
||||
import { tcp } from '@libp2p/tcp'
|
||||
import { multiaddr } from '@multiformats/multiaddr'
|
||||
import { createLibp2p } from 'libp2p'
|
||||
import { perf } from '@libp2p/perf'
|
||||
import { parseArgs } from 'node:util'
|
||||
|
||||
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} serverIpAddress
|
||||
* @param {string} transport
|
||||
* @param {number} uploadBytes
|
||||
* @param {number} downloadBytes
|
||||
*/
|
||||
export async function main (runServer, serverIpAddress, transport, uploadBytes, downloadBytes) {
|
||||
const { host, port } = splitHostPort(serverIpAddress)
|
||||
|
||||
const config = {
|
||||
transports: [
|
||||
tcp()
|
||||
],
|
||||
streamMuxers: [
|
||||
yamux()
|
||||
],
|
||||
connectionEncryption: [
|
||||
noise()
|
||||
],
|
||||
connectionManager: {
|
||||
minConnections: 0
|
||||
},
|
||||
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)
|
||||
})
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "@libp2p/perf-js-libp2p-2-4",
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@chainsafe/libp2p-noise": "^14.0.0",
|
||||
"@chainsafe/libp2p-yamux": "^6.0.1",
|
||||
"@libp2p/perf": "^3.0.4",
|
||||
"@libp2p/tcp": "^9.0.4",
|
||||
"libp2p": "^2.4.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
# In case this script is `kill`ed, `kill` its child process, namely the `node`
|
||||
# process below.
|
||||
cleanup() {
|
||||
kill $node_pid
|
||||
}
|
||||
trap cleanup EXIT TERM
|
||||
|
||||
# Find the path to the Node.js executable
|
||||
node_path=$(which node)
|
||||
|
||||
run_server=false
|
||||
server_address=""
|
||||
upload_bytes=0
|
||||
download_bytes=0
|
||||
transport=""
|
||||
|
||||
# Parse named parameters manually
|
||||
for ((i = 1; i <= $#; i++)); do
|
||||
if [ "${!i}" == "--server-address" ]; then
|
||||
server_address="${@:i+1:1}"
|
||||
fi
|
||||
if [ "${!i}" == "--upload-bytes" ]; then
|
||||
upload_bytes="${@:i+1:1}"
|
||||
fi
|
||||
if [ "${!i}" == "--download-bytes" ]; then
|
||||
download_bytes="${@:i+1:1}"
|
||||
fi
|
||||
if [ "${!i}" == "--transport" ]; then
|
||||
transport="${@:i+1:1}"
|
||||
fi
|
||||
if [ "${!i}" == "--run-server" ]; then
|
||||
run_server=true
|
||||
fi
|
||||
done
|
||||
|
||||
# Run perf
|
||||
node $(dirname "$0")/index.js --run-server=$run_server --server-address=$server_address --upload-bytes=$upload_bytes --download-bytes=$download_bytes --transport=$transport &
|
||||
|
||||
node_pid=$!
|
||||
|
||||
# Wait for `node_pid` to finish, or for it to be `kill`ed by the above
|
||||
# `cleanup`.
|
||||
wait $node_pid
|
|
@ -101,5 +101,12 @@
|
|||
"transportStacks": [
|
||||
"tcp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "v2.4",
|
||||
"implementation": "js-libp2p",
|
||||
"transportStacks": [
|
||||
"tcp"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue