-
In our p2p network where there are 2 types of nodes: RPC and Compute.
We make several measurements throughout the lifecycle of a message, as follows: sequenceDiagram
actor R as RPC
actor C as Compute
note over R: R_p = publish timestamp
R ->> C: task
note over C: C_r = receive timestamp
activate C
note right of C: C_e = execution duration
deactivate C
note over C: C_p = publish timestamp
C ->> R: result
note over R: R_r = receive timestamp
In the diagram above we have the following:
-- | ------------- | ============== | --------- | --
R_p C_r C_e C_p R_r From these, we define 4 values:
Note that the timestamps are given at application level, e.g. ProblemAssume that 3 messages are sent for the same task, so that execution times are roughly the same for each task. What we have observed is that with consecutive messages, {'publish_latency': 2, 'execution_time': 10, 'receive_latency': 8, 'roundtrip': 20}
{'publish_latency': 5, 'execution_time': 10, 'receive_latency': 5, 'roundtrip': 20}
{'publish_latency': 9, 'execution_time': 10, 'receive_latency': 1, 'roundtrip': 20} What we understand from this is that the messages are first queued in the receipt order, and the messages to be sent are queued as well. Once all tasks are finished, the receive queue is finished and send queue is consumed, sending all these messages at once. How can we prioritize For the record, we are using libp2p with GossipSub, Kademlia DHT, DCuTR. (https://github.com/firstbatchxyz/dkn-compute-node). Here is our main loop that handles swarm events. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Hi @erhant, three questions for clarification:
One thing I noticed in your code is that you stop polling the swarm while handling an gossipsub message. When the swarm is not polled, it won't make any progress. So if you receive a second publish message while the first one is still being handled, it will affect the publish latency. A solution for that would be e.g. to poll the swarm in a separate task continuously and forward the received gossipsub messages in a channel. |
Beta Was this translation helpful? Give feedback.
Small suggestion: you might still want to do the publishing of messages in the same task that polls the swarm, because otherwise you need to share the swarm in a Mutex.
So basically you p2p client would be doing all the swarm interaction:
process-task
via channelprocess-task
and callingreport_message_validation_result
examples/file-sharing might be a good starting point.