@libp2p/perf
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

@libp2p/perf

libp2p.io Discuss codecov CI

Implementation of Perf Protocol

About

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

Example

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

Browser <script> tag

Loading this module through a script tag will make it's 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.

Readme

Keywords

none

Package Sidebar

Install

npm i @libp2p/perf

Weekly Downloads

431

Version

4.0.1

License

Apache-2.0 OR MIT

Unpacked Size

46.2 kB

Total Files

20

Last publish

Collaborators

  • jacobheun
  • npm-service-account-libp2p
  • alanshaw
  • vascosantos
  • achingbrain
  • daviddias