forked from libp2p/test-plans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: re-enable js-libp2p under node.js (libp2p#325)
Adds perf tests for js-libp2p 0.46.x and 1.0 (via the `next` tag). --------- Co-authored-by: achingbrain <[email protected]>
- Loading branch information
1 parent
7ca92e8
commit 9a4c969
Showing
13 changed files
with
19,863 additions
and
11,388 deletions.
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 |
---|---|---|
@@ -1,19 +1,12 @@ | ||
NPM_PACKAGE_VERSION := 1.1.6 | ||
NPM_PACKAGE := @libp2p/perf | ||
NPM_PACKAGE_NAME := $(NPM_PACKAGE)@$(NPM_PACKAGE_VERSION) | ||
|
||
SOURCE_DIR := js-libp2p-protocol-perf | ||
|
||
DOCKER_IMAGE := node:18.17.1 | ||
DOCKER_RUN := docker run --rm -v "$(shell pwd)/$(SOURCE_DIR)":/usr/src/myapp -w /usr/src/myapp $(DOCKER_IMAGE) | ||
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: | ||
mkdir -p $(SOURCE_DIR) | ||
$(DOCKER_RUN) npm install $(NPM_PACKAGE_NAME) | ||
$(DOCKER_RUN) npm ci | ||
|
||
clean: | ||
rm -rf js-libp2p-* | ||
rm -rf node_modules | ||
|
||
.PHONY: all clean perf |
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,104 @@ | ||
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 { perfService } 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: perfService() | ||
} | ||
} | ||
|
||
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) | ||
}) |
Oops, something went wrong.