libp2p
    Preparing search index...

    Module @libp2p/perf

    The Perf service implements the perf protocol, which can be used to measure transfer performance within and across libp2p implementations.

    import { noise } from '@chainsafe/libp2p-noise'
    import { yamux } from '@chainsafe/libp2p-yamux'
    import { tcp } from '@libp2p/tcp'
    import { createLibp2p, type Libp2p } from 'libp2p'
    import { plaintext } from '@libp2p/plaintext'
    import { perf, type Perf } from '@libp2p/perf'

    const ONE_MEG = 1024 * 1024
    const UPLOAD_BYTES = ONE_MEG * 1024
    const DOWNLOAD_BYTES = ONE_MEG * 1024

    async function createNode (): Promise<Libp2p<{ perf: Perf }>> {
    return createLibp2p({
    addresses: {
    listen: [
    '/ip4/0.0.0.0/tcp/0'
    ]
    },
    transports: [
    tcp()
    ],
    connectionEncrypters: [
    noise(), plaintext()
    ],
    streamMuxers: [
    yamux()
    ],
    services: {
    perf: perf()
    }
    })
    }

    const libp2p1 = await createNode()
    const libp2p2 = await createNode()

    for await (const output of libp2p1.services.perf.measurePerformance(libp2p2.getMultiaddrs()[0], UPLOAD_BYTES, DOWNLOAD_BYTES)) {
    console.info(output)
    }

    await libp2p1.stop()
    await libp2p2.stop()

    Interfaces

    Perf
    PerfComponents
    PerfInit
    PerfOptions
    PerfOutput

    Functions

    perf