From 230cfd60334359bc61674b062dc3c723ff16ebfc Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 11 Aug 2023 14:05:32 -0500 Subject: [PATCH 01/12] fix(protocol-perf): output close listening node after latency is output --- packages/protocol-perf/src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index 33c96e6a92..93e7155e47 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -103,10 +103,10 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo const duration = await node.services.perf.measurePerformance(startTime, connection as Connection, BigInt(uploadBytes), BigInt(downloadBytes)) - await node.stop() - // eslint-disable-next-line no-console console.log('latency: ' + JSON.stringify({ latency: duration })) + + await node.stop() } function splitHostPort (address: string): { host: string, port?: string } { From 94c11a0f238df5177d0a00da7c7d82fb87c0c735 Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 11 Aug 2023 14:28:48 -0500 Subject: [PATCH 02/12] fix(@protocol-perf): don't shutdown node --- packages/protocol-perf/src/main.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index 93e7155e47..1b7b3c2e7c 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -105,8 +105,6 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo // eslint-disable-next-line no-console console.log('latency: ' + JSON.stringify({ latency: duration })) - - await node.stop() } function splitHostPort (address: string): { host: string, port?: string } { From f88ee492a7d32dd52cdd1c5753845537bfb65de1 Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 11 Aug 2023 15:43:05 -0500 Subject: [PATCH 03/12] fix: removed extra string from latency + check for conneciton status --- packages/protocol-perf/src/main.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index 1b7b3c2e7c..1aadf29514 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -99,12 +99,14 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo connection = await node.dial(multiaddr(tcpMultiaddrAddress)) } - await pWaitFor(() => connection != null) + await pWaitFor(() => connection != null && connection.status !== 'closed') const duration = await node.services.perf.measurePerformance(startTime, connection as Connection, BigInt(uploadBytes), BigInt(downloadBytes)) // eslint-disable-next-line no-console - console.log('latency: ' + JSON.stringify({ latency: duration })) + console.log(JSON.stringify({ latency: duration })) + + await node.stop() } function splitHostPort (address: string): { host: string, port?: string } { From aa26393a1fb10f2409f57c026a538abb387f70aa Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 11 Aug 2023 16:15:39 -0500 Subject: [PATCH 04/12] test: only kill the client not server --- packages/protocol-perf/src/main.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index 1aadf29514..fc2a09d467 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -106,7 +106,9 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo // eslint-disable-next-line no-console console.log(JSON.stringify({ latency: duration })) - await node.stop() + if (!runServer){ + await node.stop() + } } function splitHostPort (address: string): { host: string, port?: string } { From af81fa8d05d195ac690b9e380f4f249a2fdafcaf Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 11 Aug 2023 16:57:18 -0500 Subject: [PATCH 05/12] fix: switch to mplex --- packages/protocol-perf/src/main.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index fc2a09d467..c4a4628787 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -1,4 +1,4 @@ -import { yamux } from '@chainsafe/libp2p-yamux' +import { mplex } from '@libp2p/mplex' import { unmarshalPrivateKey } from '@libp2p/crypto/keys' import { createFromPrivKey } from '@libp2p/peer-id-factory' import { tcp } from '@libp2p/tcp' @@ -57,7 +57,7 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo const config = { transports: [tcp()], - streamMuxers: [yamux()], + streamMuxers: [mplex()], connectionEncryption: [ plaintext() ], @@ -99,16 +99,14 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo connection = await node.dial(multiaddr(tcpMultiaddrAddress)) } - await pWaitFor(() => connection != null && connection.status !== 'closed') + await pWaitFor(() => connection != null) const duration = await node.services.perf.measurePerformance(startTime, connection as Connection, BigInt(uploadBytes), BigInt(downloadBytes)) // eslint-disable-next-line no-console console.log(JSON.stringify({ latency: duration })) - if (!runServer){ - await node.stop() - } + await node.stop() } function splitHostPort (address: string): { host: string, port?: string } { From f313ec5625f919b89995c450c30018b59bf8eff4 Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 11 Aug 2023 17:00:21 -0500 Subject: [PATCH 06/12] chore: linting + dep check --- packages/protocol-perf/package.json | 2 +- packages/protocol-perf/src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol-perf/package.json b/packages/protocol-perf/package.json index e7f6c7577c..a289a3766f 100644 --- a/packages/protocol-perf/package.json +++ b/packages/protocol-perf/package.json @@ -47,13 +47,13 @@ "renderResults": "node dist/src/renderResults.js" }, "dependencies": { - "@chainsafe/libp2p-yamux": "^5.0.0", "@libp2p/crypto": "^2.0.0", "@libp2p/interface": "^0.1.0", "@libp2p/interface-compliance-tests": "^4.0.0", "@libp2p/interface-internal": "^0.1.0", "@libp2p/interfaces": "3.3.2", "@libp2p/logger": "^3.0.0", + "@libp2p/mplex": "^9.0.2", "@libp2p/peer-id-factory": "3.0.0", "@libp2p/tcp": "^8.0.0", "@multiformats/multiaddr": "^12.1.5", diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index c4a4628787..2e9b6a79ed 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -1,5 +1,5 @@ -import { mplex } from '@libp2p/mplex' import { unmarshalPrivateKey } from '@libp2p/crypto/keys' +import { mplex } from '@libp2p/mplex' import { createFromPrivKey } from '@libp2p/peer-id-factory' import { tcp } from '@libp2p/tcp' import { multiaddr } from '@multiformats/multiaddr' From 4a14e3be54873fe76ed91227f3b829fad16803fa Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 14 Aug 2023 10:47:50 -0500 Subject: [PATCH 07/12] fix: ensure that the client drives performance measurement --- packages/protocol-perf/src/main.ts | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index 2e9b6a79ed..7f1d16ca1f 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -5,12 +5,10 @@ import { tcp } from '@libp2p/tcp' import { multiaddr } from '@multiformats/multiaddr' import { createLibp2p } from 'libp2p' import { plaintext } from 'libp2p/insecure' -import pWaitFor from 'p-wait-for' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import yargs from 'yargs' import { hideBin } from 'yargs/helpers' import { defaultInit, perfService } from '../src/index.js' -import type { Connection } from '@libp2p/interface/connection' const argv = yargs(hideBin(process.argv)) .options({ @@ -89,24 +87,13 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo const startTime = Date.now() - let connection: any = null - - if (runServer) { - node.addEventListener('connection:open', (eventInfo) => { - connection = eventInfo.detail - }) - } else { - connection = await node.dial(multiaddr(tcpMultiaddrAddress)) + if (!runServer) { + const connection = await node.dial(multiaddr(tcpMultiaddrAddress)) + const duration = await node.services.perf.measurePerformance(startTime, connection, BigInt(uploadBytes), BigInt(downloadBytes)) + // eslint-disable-next-line no-console + console.log(JSON.stringify({ latency: duration/1000 })) + await node.stop() } - - await pWaitFor(() => connection != null) - - const duration = await node.services.perf.measurePerformance(startTime, connection as Connection, BigInt(uploadBytes), BigInt(downloadBytes)) - - // eslint-disable-next-line no-console - console.log(JSON.stringify({ latency: duration })) - - await node.stop() } function splitHostPort (address: string): { host: string, port?: string } { From cc29c07a1adf74c17994abf1ac9ff47f1c08ed62 Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 14 Aug 2023 10:56:46 -0500 Subject: [PATCH 08/12] chore: linting --- packages/protocol-perf/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index 7f1d16ca1f..ad314806d8 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -91,7 +91,7 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo const connection = await node.dial(multiaddr(tcpMultiaddrAddress)) const duration = await node.services.perf.measurePerformance(startTime, connection, BigInt(uploadBytes), BigInt(downloadBytes)) // eslint-disable-next-line no-console - console.log(JSON.stringify({ latency: duration/1000 })) + console.log(JSON.stringify({ latency: duration / 1000 })) await node.stop() } } From 4f738aa1a07571db9119bbaf62b426fe1e5a344b Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 14 Aug 2023 10:58:17 -0500 Subject: [PATCH 09/12] deps: remove unused dep --- packages/protocol-perf/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/protocol-perf/package.json b/packages/protocol-perf/package.json index a289a3766f..30fe510c5c 100644 --- a/packages/protocol-perf/package.json +++ b/packages/protocol-perf/package.json @@ -58,7 +58,6 @@ "@libp2p/tcp": "^8.0.0", "@multiformats/multiaddr": "^12.1.5", "libp2p": "^0.46.3", - "p-wait-for": "^5.0.2", "uint8arrays": "^4.0.6", "yargs": "^17.7.2" }, From fabf5c8532e8aca2850639f4c49a29bcb2f3e1e8 Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 14 Aug 2023 13:15:10 -0500 Subject: [PATCH 10/12] test: reintroduce yamux --- package.json | 5 ++++- packages/protocol-perf/src/main.ts | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b36a7e5759..efea17ceb0 100644 --- a/package.json +++ b/package.json @@ -50,5 +50,8 @@ "examples/*", "interop", "packages/*" - ] + ], + "dependencies": { + "@chainsafe/libp2p-yamux": "^5.0.0" + } } diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index ad314806d8..ffec1aca46 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -1,5 +1,4 @@ import { unmarshalPrivateKey } from '@libp2p/crypto/keys' -import { mplex } from '@libp2p/mplex' import { createFromPrivKey } from '@libp2p/peer-id-factory' import { tcp } from '@libp2p/tcp' import { multiaddr } from '@multiformats/multiaddr' @@ -9,6 +8,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import yargs from 'yargs' import { hideBin } from 'yargs/helpers' import { defaultInit, perfService } from '../src/index.js' +import { yamux } from '@chainsafe/libp2p-yamux' const argv = yargs(hideBin(process.argv)) .options({ @@ -55,7 +55,7 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo const config = { transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux()], connectionEncryption: [ plaintext() ], @@ -91,6 +91,7 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo const connection = await node.dial(multiaddr(tcpMultiaddrAddress)) const duration = await node.services.perf.measurePerformance(startTime, connection, BigInt(uploadBytes), BigInt(downloadBytes)) // eslint-disable-next-line no-console + // Output latency in seconds console.log(JSON.stringify({ latency: duration / 1000 })) await node.stop() } From a55892dce15b9d058323bae5255a0206804ad288 Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 14 Aug 2023 13:22:18 -0500 Subject: [PATCH 11/12] chore: linting --- packages/protocol-perf/package.json | 1 - packages/protocol-perf/src/main.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/protocol-perf/package.json b/packages/protocol-perf/package.json index b420211831..69597e47e6 100644 --- a/packages/protocol-perf/package.json +++ b/packages/protocol-perf/package.json @@ -58,7 +58,6 @@ "@libp2p/tcp": "^8.0.3", "@multiformats/multiaddr": "^12.1.5", "libp2p": "^0.46.4", - "p-wait-for": "^5.0.2", "uint8arrays": "^4.0.6", "yargs": "^17.7.2" }, diff --git a/packages/protocol-perf/src/main.ts b/packages/protocol-perf/src/main.ts index ffec1aca46..f994fdc015 100644 --- a/packages/protocol-perf/src/main.ts +++ b/packages/protocol-perf/src/main.ts @@ -1,3 +1,4 @@ +import { yamux } from '@chainsafe/libp2p-yamux' import { unmarshalPrivateKey } from '@libp2p/crypto/keys' import { createFromPrivKey } from '@libp2p/peer-id-factory' import { tcp } from '@libp2p/tcp' @@ -8,7 +9,6 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import yargs from 'yargs' import { hideBin } from 'yargs/helpers' import { defaultInit, perfService } from '../src/index.js' -import { yamux } from '@chainsafe/libp2p-yamux' const argv = yargs(hideBin(process.argv)) .options({ @@ -90,8 +90,8 @@ export async function main (runServer: boolean, serverIpAddress: string, transpo if (!runServer) { const connection = await node.dial(multiaddr(tcpMultiaddrAddress)) const duration = await node.services.perf.measurePerformance(startTime, connection, BigInt(uploadBytes), BigInt(downloadBytes)) + // Output latency to stdout in seconds // eslint-disable-next-line no-console - // Output latency in seconds console.log(JSON.stringify({ latency: duration / 1000 })) await node.stop() } From c9d473468a8af8e591014887495c6ee5237e7424 Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 14 Aug 2023 13:23:38 -0500 Subject: [PATCH 12/12] deps: remove accidental dep --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index efea17ceb0..b36a7e5759 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,5 @@ "examples/*", "interop", "packages/*" - ], - "dependencies": { - "@chainsafe/libp2p-yamux": "^5.0.0" - } + ] }