This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
Bitswap Sessions Exploration #165
Comments
@Stebalien and @hannahhoward I created this issue to make sure I understand the current state of Bitswap sessions before thinking about how to iterate on improving performance. Please read over it and let me know if there are any inaccuracies or things that can be clarified. |
To the best of my knowledge, that looks correct. |
This was referenced Aug 2, 2019
@daviddias @hannahhoward @whyrusleeping it would be super helpful to have your ideas on the issues linked to this issue: #166 #167 #168 |
Implemented as part of ipfs/kubo#6782 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Bitswap sessions group together requests for related blocks (eg the blocks that make up a file) to take advantage of the fact that usually related blocks can be retrieved from the same peers.
This Issue describes the current implementation of sessions.
Background
In IPFS a file is broken up into blocks that are organized into a DAG. The file is identified by the CID of the block representing the DAG root. To fetch a file:
If these requests are all made using a single Bitswap session, the session remembers which peers have responded before, how "far" each peer is (in terms of network latency) and manages splitting the requests across peers and combining the responses.
Session Implementation
Timers
The session maintains two timers:
idle timer (1 second by default)
The idle interval triggers after 1 second by default. Once at least one peer has responded to a request, the idle interval is set to
500ms + (3 x the average latency)
, with an increasing back-off each time the idle timer is triggered (if no block was received in the interim).periodic search timer (1 minute by default)
Request sharding
Peer list
As peers are discovered, they are added to a peer list. Each request to a peer is timed, and the latency for the peer is adjusted according to the formula:
latency = <current latency> * 0.5 + <new latency> * 0.5
Live wants
The session maintains a list of "live" wants, ie requests for a CID that have not yet been fulfilled. There can be up to 32 live wants at a time.
Requests are made when
GetBlock()
orGetBlocks()
The CIDs that were added to the live want queue are sent out as a want request
Request Splitting
The first want request is broadcast to all peers that this node is connected to. As responses come in, the peers are added to the peer list in order of latency.
Once there are peers in the peer list, any subsequent want request
For example if there are 8 peers (A - H) and 10 CIDs (0 - 9), and the split factor is 3:
Often more than one peer will have the same block (eg peers
A
&D
might both havecid0
). When the local node receives a block, it broadcasts a cancel message for that block CID to all connected peers. However the cancel may not be processed by the recipient peer before it has sent out the block, meaning the local node will receive a duplicate of the block. The local node keeps track of the ratio ofduplicates / received blocks
and adjusts the split factor:The split factor is initially set to 2 and can range from 1 - 16.
Currently the peer list is ordered linearly by latency, however there is a WIP PR to adjust the list order probabilistically according to latency.
The text was updated successfully, but these errors were encountered: