Skip to content
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

Large message handling combined #1234

Draft
wants to merge 15 commits into
base: p2p-research
Choose a base branch
from

Conversation

ufarooqstatus
Copy link
Collaborator

We use message preamble to detect incoming messages. This information is used to:

  • Announce the messages we are receiving to full-message mesh using IMReceiving messages.
  • Make IWANT requests only if we are not already receiving the same message
  • Limit outstanding IWANT requests for a message to 1
  • Stagger (only add small delay) mesh transmissions

PoC implementation for shadow simulation. Not intended for merging
Reduces duplicates to less than 1.5 for large messages

More details here

Copy link

Pull requests titles must follow the Conventional Commits specification

Copy link

Commits must follow the Conventional Commits specification
Please fix these commit messages:

some coments added
preamble added in IWANT replies also
topicID added in preamble
sem is one (sequential send in staggering)
Added control preamble, and staggering. Still need to add preamble for iwants
stagger send during publish and validateAndRelay. Still need to add timeouts
staggering added in message relay, still need to adjust timeouts
corrected dup_during_validation count
Merge branch 'master' into lma_merge_imreceiving_iwant_1 updating local branch
we make only one iwant request
set num_finds to 1
imreceiving handling merged with iwant optimization
IMReceiving message added
stats places, warmup messages added

@ufarooqstatus ufarooqstatus marked this pull request as draft January 10, 2025 12:47
Copy link
Member

@richard-ramos richard-ramos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting PR!

Is this PR also implementing this part of the spec?:

if the message ID is found in the ongoing_receives list,
the peer should postpone sending the IWANT request for a defer_interval.
The defer_interval may be based on the message download time.

@@ -226,6 +253,7 @@ method init*(g: GossipSub) =
g.codecs &= GossipSubCodec_12
g.codecs &= GossipSubCodec_11
g.codecs &= GossipSubCodec_10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this change result in a GossipSubCodec_14 as described in libp2p/specs#654 ?

@@ -782,7 +873,25 @@ method publish*(g: GossipSub, topic: string, data: seq[byte]): Future[int] {.asy

g.mcache.put(msgId, msg)

g.broadcast(peers, RPCMsg(messages: @[msg]), isHighPriority = true)
#g.broadcast(peers, RPCMsg(messages: @[msg]), isHighPriority = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️ ?

Suggested change
#g.broadcast(peers, RPCMsg(messages: @[msg]), isHighPriority = true)

#g.broadcast(peers, RPCMsg(messages: @[msg]), isHighPriority = true)
let sem = newAsyncSemaphore(1)
var staggerPeers = toSeq(peers)
g.rng.shuffle(staggerPeers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the peers randomly sorted?

Comment on lines +881 to +894
#We send message immediately after sending preamble to each peer
proc sendToOne(p: PubSubPeer) {.async.} =
g.broadcast(@[p], RPCMsg(control: some(ControlMessage(
preamble: @[ControlIHave(topicID: topic, messageIDs: @[msgId])]
))), isHighPriority = true)

await sem.acquire()
defer: sem.release()

g.broadcast(@[p], RPCMsg(messages: @[msg]), isHighPriority = false)

for p in staggerPeers:
asyncSpawn sendToOne(p)

Copy link
Member

@richard-ramos richard-ramos Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the AsyncSemaphore(1) means that the preambles are being sent sequentially to each peer, right? Why is this the case? Shouldn't we try to get the preamble messages being sent concurrently to all peers?

await sem.acquire()
defer: sem.release()

g.broadcast(@[p], RPCMsg(messages: @[msg]), isHighPriority = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No isHighPriority = true?

Comment on lines +386 to +393
return result
continue
let msg = g.mcache.get(mid).valueOr:
libp2p_gossipsub_received_iwants.inc(1, labelValues = ["unknown"])
continue
libp2p_gossipsub_received_iwants.inc(1, labelValues = ["correct"])
messages.add(msg)
return messages
result.messages.add(msg)
result.ids.add(mid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to define a messages and ids variables, instead of using result. See https://status-im.github.io/nim-style-guide/language.result.html

Comment on lines +362 to +363
if peer.heIsReceivings[^1].len > 1000: break
if messageId.len > 100: continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do messageIds exceed 100? I'm wondering if this condition should be added in other places as i haven't seen length checking for messageIds using 100. (Probably a good idea to extract this into a constant too)

Comment on lines +66 to +67
preamble*: seq[ControlIHave]
imreceiving*: seq[ControlIWant]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these have their own type? ControlPreamble and ControlImReceiving?

#We send message immediately after sending preamble to each peer
proc sendToOne(p: PubSubPeer) {.async.} =
g.broadcast(@[p], RPCMsg(control: some(ControlMessage(
preamble: @[ControlIHave(topicID: topic, messageIDs: @[msgId])]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending the message length is still pending, right?

await sem.acquire()
defer: sem.release()

g.broadcast(@[p], RPCMsg(messages: @[msg]), isHighPriority = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading in the specs, I see the following:

Adding a message preamble may increase control overhead for small messages.
Therefore, it is preferable to use it only for messages that exceed the preamble_threshold.

The way it is coded right now, it will send the preamble always, right? Is this because this PR is for experiments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Experimental
Development

Successfully merging this pull request may close these issues.

None yet

2 participants