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

Performance optimization: create a new torrent repository using a SkipMap instead of a BTreeMap #777

Closed
josecelano opened this issue Apr 5, 2024 · 0 comments · Fixed by #778
Assignees
Labels
Optimization Make it Faster

Comments

@josecelano
Copy link
Member

Relates to: #774

To simplify the description of the issue, we can say that we are using a torrent repository like this:

type TorrentRepository = BTreeMap<InfoHash, TorrentEntry>

struct TorrentEntry {
  peers: BTreeMap<PeerId, Peer>,
  downloaded: u32,
}

Check the discussion for more details.

One performance optimization proposal was to replace the outer BTreeMap with a data structure that allows for the simultaneous insertion of new torrents.

Another issue is trying with a different structure: a DashMap.

DashMap is based on sharding and does not keep the order of items. The other issues have not been merged yet because we need the order for the API. However, we are also discussing if we need to keep the order and what order to use.
The DashMap API is also very different to the BTreeMap one.

On the other hand, SkipMap API is very similar to the BTreeMap, and it keeps items ordered. Since the effort to implement was not too big I decided to do it.

SkipMap is being used in other trackers in Rust (https://github.com/Power2All/torrust-actix).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Optimization Make it Faster
Projects
None yet
1 participant