Latency

Overview

To assess the latency and health of your P2P network, you can leverage the built-in ping protocol. This mechanism allows you to measure the round-trip operation timeframe.

The ping protocol is actively running in your network.

  1. Send a ping message to a given peer.

  2. Wait for a response.

  3. Measure the time elapsed during the operation.

The stack logs the latency automatically, assuming the appropriate debug logs are enabled.

Example Logs

When debug logging is enabled, you'll see entries like the following in your logs:

[2025-04-15 08:19:49]:[v1.10.0]:[debug]:: 2025-04-15T08:19:49.919Z libp2p:ping incoming ping from 12D3KooWAQ8UrZkbDCyPSyRWrzPbn9vP5pMoV1F8hXi6AMVFKYqE complete in 54ms
[2025-04-15 08:19:49]:[v1.10.0]:[debug]:: 2025-04-15T08:19:49.098Z libp2p:ping incoming ping from 12D3KooWSJw4HjLba4Fp63DT3jCiGYf9fBQQ1mvP6LLJogZGxzmC complete in 8ms
[2025-04-15 08:19:48]:[v1.10.0]:[debug]:: 2025-04-15T08:19:48.577Z libp2p:ping incoming ping from 12D3KooWH45THrNhhDSNMzWcaxQ39ydQ5WqXfku7j396c4JDAt8C complete in 30ms

Latency between peers can be influenced by:

  • Geographical distribution

  • Network routing

  • NAT traversal complexity

  • ISP conditions

  • Transport layers (WebSockets, QUIC, TCP, etc.)

Enabling Debug Logs

Enable the libp2p:ping debug namespace. This can be done by setting the following environment variable before starting your node:

DEBUG=libp2p:ping*

For detailed diagnostics (e.g. libp2p:gossipsub, libp2p:connection-manager)

DEBUG=libp2p:*

Last updated