Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

feat: add message byte batching #235

Merged
merged 3 commits into from
Nov 25, 2022
Merged

Conversation

achingbrain
Copy link
Member

Adds a new setting minSendBytes that is undefined by default.

If undefined all messages sent through multiplexed streams will be serialized and sent over the wire immediately.

If set to a number, it will be used as a byte value, and the serialized bytes of all messages sent during the current tick will be buffered up to that value.

Once either the buffer lengths hits that value or the next tick begins, all bytes in the buffer will be sent over the wire.

Adds a new setting `minSendBytes` that is `undefined` by default.

If `undefined` all messages sent through multiplexed streams will
be serialized and sent over the wire immediately.

If set to a number, it will be used as a byte value, and the
serialized bytes of all messages sent during the current tick will
be buffered up to that value.

Once either the buffer lengths hits that value or the next tick
begins, all bytes in the buffer will be sent over the wire.
src/encode.ts Outdated Show resolved Hide resolved
@achingbrain
Copy link
Member Author

achingbrain commented Nov 24, 2022

There are some gains to be had for small message sizes though they evaporate once messages sizes get above about 10kb.

Partially you'd expect this as the buffered message data is yielded as soon as it goes above minSendBytes so if it's set at 10kb and you're sending 11kb messages there's no more buffering.

The graph below was generated using the benchmarks in https://github.com/ipfs-shipyard/js-libp2p-transfer-performance

The test sends 105MB of data from one node to another over TCP divided across a number of messages. The x-axis is individual message sizes, the y-axis is how long it takes to send that much data. The legend on the right is the value of minSendBytes for each test - 1kb - 10MB.

image

@mpetrunic mpetrunic merged commit 4e2a49d into master Nov 25, 2022
@mpetrunic mpetrunic deleted the feat/add-message-byte-batching branch November 25, 2022 12:01
github-actions bot pushed a commit that referenced this pull request Nov 25, 2022
## [7.1.0](v7.0.7...v7.1.0) (2022-11-25)

### Features

* add message byte batching ([#235](#235)) ([4e2a49d](4e2a49d))
@github-actions
Copy link

🎉 This PR is included in version 7.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants