-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add traceFunction call to metrics
Allow tracing method calls using a metrics implementation. ```js const libp2p = await createLibp2p() const context = libp2p.metrics?.createTraceContext() for await (const foo of libp2p.contentRouting.findProviders(cid, { context, signal: AbortSignal.timeout(20_000) }) { //... } ``` Adds tracing support to `libp2p.contentRouting.*` and `libp2p.peerRouting.*` to start with, other methods can have it added when necessary.
- Loading branch information
1 parent
7caee9f
commit 73887f2
Showing
15 changed files
with
24,334 additions
and
12 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
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
24,006 changes: 24,006 additions & 0 deletions
24,006
packages/kad-dht/benchmark/peer-distance/fixtures.js
Large diffs are not rendered by default.
Oops, something went wrong.
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,56 @@ | ||
/* eslint-disable no-console | ||
import Benchmark from 'benchmark' | ||
import { PeerDistanceList } from '../../dist/src/peer-distance-list.js' | ||
import { generateKeyPair } from '@libp2p/crypto/keys' | ||
import { peerIdFromPrivateKey } from '@libp2p/peer-id' | ||
import { convertPeerId } from '../../dist/src/utils.js' | ||
const peers = 6000 | ||
for (let i = 0; i < peers; i++) { | ||
const key = await generateKeyPair('Ed25519') | ||
const id = peerIdFromPrivateKey(key) | ||
console.info(`{ | ||
peerId: peerIdFromString('${id.toString()}'), | ||
kadId: Uint8Array.from([${(await convertPeerId(id)).join(', ')}]) | ||
}, `) | ||
} | ||
*/ | ||
|
||
|
||
|
||
/* eslint-disable no-console */ | ||
import Benchmark from 'benchmark' | ||
import { PeerDistanceList } from '../../dist/src/peer-distance-list.js' | ||
import { convertBuffer } from '../../dist/src/utils.js' | ||
import { key, peers } from './fixtures.js' | ||
|
||
const suite = new Benchmark.Suite('peer distance list') | ||
|
||
suite.add('current', async (d) => { | ||
const kadId = await convertBuffer(key) | ||
const list = new PeerDistanceList(kadId, 20) | ||
|
||
for (const peer of peers) { | ||
list.addWitKadId({ id: peer.peerId, multiaddrs: [] }, peer.kadId) | ||
} | ||
|
||
d.resolve() | ||
}, { defer: true }) | ||
|
||
async function main () { | ||
suite | ||
.on('cycle', (event) => console.log(String(event.target))) | ||
.on('complete', function () { | ||
console.log('fastest is ' + this.filter('fastest').map('name')) | ||
}) | ||
.run({ async: true }) | ||
} | ||
|
||
main() | ||
.catch(err => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
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,14 @@ | ||
{ | ||
"name": "libp2p-kad-dht-peer-distance-list-benchmarks", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"start": "node ." | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@types/benchmark": "^2.1.5", | ||
"benchmark": "^2.1.4" | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.