-
Notifications
You must be signed in to change notification settings - Fork 201
Open
Description
Summary
Implement the libp2p perf protocol in py-libp2p to enable standardized performance benchmarking between libp2p implementations.
Background
The perf protocol (/perf/1.0.0) is a simple protocol for measuring transfer performance within and across libp2p implementations. It allows measuring:
- Connection establishment time
- Upload throughput
- Download throughput
This protocol is already implemented in:
- js-libp2p (Note: "Handshakes per second" benchmark from the spec is not implemented)
Proposed API
from libp2p import new_host
from libp2p.perf import Perf, PROTOCOL_ID
# Create hosts
server_host = new_host()
client_host = new_host()
# Server side
perf_server = Perf(server_host)
await perf_server.start()
# Client side - run benchmark
perf_client = Perf(client_host)
result = await perf_client.measure_performance(
peer_id=server_peer_id,
multiaddr=server_addr,
send_bytes=1024 * 1024, # 1 MB upload
recv_bytes=1024 * 1024, # 1 MB download
)
print(f"Time: {result.time_seconds:.3f}s")
print(f"Upload: {result.upload_bytes / result.time_seconds / 1024:.2f} KB/s")
print(f"Download: {result.download_bytes / result.time_seconds / 1024:.2f} KB/s")Protocol Specification
Per the spec:
- Client opens stream with
/perf/1.0.0 - Client sends 8-byte big-endian uint64:
n(bytes to receive back) - Client sends upload data
- Client half-closes stream (signals EOF)
- Server reads all upload data
- Server sends
nbytes back - Server closes stream
Related
- libp2p perf spec: https://github.com/libp2p/specs/blob/master/perf/perf.md
- js-libp2p implementation: https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-perf
- Interop tests: https://github.com/libp2p/test-plans/tree/master/perf
Are you planning to do it yourself in a pull request?
yes
Metadata
Metadata
Assignees
Labels
No labels