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()

    @libp2p/perf

    libp2p.io Discuss codecov CI

    Implementation of Perf Protocol

    About

    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()

    Install

    $ npm i @libp2p/perf
    

    Loading this module through a script tag will make its exports available as Libp2pPerf in the global namespace.

    <script src="https://unpkg.com/@libp2p/perf/dist/index.min.js"></script>
    

    API Docs

    License

    Licensed under either of

    Contribution

    Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

    Interfaces

    Perf
    PerfComponents
    PerfInit
    PerfOptions
    PerfOutput

    Functions

    perf