-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: pre-emptive stream creation for protocols #1516
Conversation
size-limit report 📦
|
7911491
to
14f5190
Compare
14f5190
to
9896fc0
Compare
54d61d2
to
6497428
Compare
"optimistic" is already coined to describe when libp2p client start sending data over a new stream without waiting for the remote peer to confirm stream creation. |
private handlePeerUpdateStreamPool = (evt: CustomEvent<PeerUpdate>): void => { | ||
const peer = evt.detail.peer; | ||
if (peer.protocols.includes(this.multicodec)) { | ||
this.log(`Optimistically opening a stream to ${peer.id.toString()}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-emptively
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently create streams with remote peers for a protocol lazily. ie, for eg, when
lightpush.send()
is called, a stream is created then - thus adding to the time delays for thesend()
function.This was also flagged as a problem in #1465.
This PR thus introduces the concept of optimistic streams for protocols. The idea is to open streams with peers upon connection for protocols optimistically in advance. These existing streams can then be used for requests, instead of creating new ones adhoc.
Results:
Messages sent at an interval of 200ms rapidly over lightpush to the node
/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm
:Now:
Before: