mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
announce handler: keep mutable access to torrent map less time
This commit is contained in:
parent
b40d205ccd
commit
910accad31
3 changed files with 29 additions and 28 deletions
3
TODO.md
3
TODO.md
|
|
@ -17,9 +17,6 @@
|
|||
* Performance
|
||||
* cpu-target=native good?
|
||||
* mialloc good?
|
||||
* TorrentMap: mutable access only to insert peer, then drop reference
|
||||
and get read-only access to gather peers. This could speed up
|
||||
multi-threaded performance a lot
|
||||
* Use less bytes from PeerId for hashing? Would need to implement
|
||||
"faulty" PartialEq too (on PeerMapKey, which would be OK)
|
||||
* bittorrent_udp
|
||||
|
|
|
|||
|
|
@ -59,10 +59,6 @@ pub fn handle_announce_requests(
|
|||
return None;
|
||||
}
|
||||
|
||||
let mut torrent_data = state.torrents
|
||||
.entry(request.info_hash)
|
||||
.or_insert_with(|| TorrentData::default());
|
||||
|
||||
let peer_key = PeerMapKey {
|
||||
ip: src.ip(),
|
||||
peer_id: request.peer_id,
|
||||
|
|
@ -70,12 +66,25 @@ pub fn handle_announce_requests(
|
|||
|
||||
let peer = Peer::from_announce_and_ip(&request, src.ip());
|
||||
let peer_status = peer.status;
|
||||
|
||||
let opt_removed_peer = if peer.status == PeerStatus::Stopped {
|
||||
torrent_data.peers.remove(&peer_key)
|
||||
} else {
|
||||
torrent_data.peers.insert(peer_key, peer)
|
||||
|
||||
let opt_removed_peer_status = {
|
||||
let mut torrent_data = state.torrents
|
||||
.entry(request.info_hash)
|
||||
.or_insert_with(|| TorrentData::default());
|
||||
|
||||
if peer_status == PeerStatus::Stopped {
|
||||
torrent_data.peers.remove(&peer_key)
|
||||
.map(|peer| peer.status)
|
||||
} else {
|
||||
torrent_data.peers.insert(peer_key, peer)
|
||||
.map(|peer| peer.status)
|
||||
}
|
||||
};
|
||||
|
||||
let max_num_peers_to_take = (request.peers_wanted.0.max(0) as usize)
|
||||
.min(config.max_response_peers);
|
||||
|
||||
let torrent_data = state.torrents.get(&request.info_hash).unwrap();
|
||||
|
||||
match peer_status {
|
||||
PeerStatus::Leeching => {
|
||||
|
|
@ -87,21 +96,16 @@ pub fn handle_announce_requests(
|
|||
PeerStatus::Stopped => {}
|
||||
};
|
||||
|
||||
if let Some(removed_peer) = opt_removed_peer {
|
||||
match removed_peer.status {
|
||||
PeerStatus::Leeching => {
|
||||
torrent_data.num_leechers.fetch_sub(1, Ordering::SeqCst);
|
||||
},
|
||||
PeerStatus::Seeding => {
|
||||
torrent_data.num_seeders.fetch_sub(1, Ordering::SeqCst);
|
||||
},
|
||||
PeerStatus::Stopped => {}
|
||||
}
|
||||
match opt_removed_peer_status {
|
||||
Some(PeerStatus::Leeching) => {
|
||||
torrent_data.num_leechers.fetch_sub(1, Ordering::SeqCst);
|
||||
},
|
||||
Some(PeerStatus::Seeding) => {
|
||||
torrent_data.num_seeders.fetch_sub(1, Ordering::SeqCst);
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let max_num_peers_to_take = (request.peers_wanted.0.max(0) as usize)
|
||||
.min(config.max_response_peers);
|
||||
|
||||
let response_peers = extract_response_peers(
|
||||
&mut rng,
|
||||
&torrent_data.peers,
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
//! ```
|
||||
//! ## Average results over 10 rounds
|
||||
//!
|
||||
//! Connect handler: 2 351 042 requests/second, 425.85 ns/request
|
||||
//! Announce handler: 266 609 requests/second, 3754.52 ns/request
|
||||
//! Scrape handler: 463 222 requests/second, 2161.85 ns/request
|
||||
//! Connect handler: 2 330 506 requests/second, 429.30 ns/request
|
||||
//! Announce handler: 264 596 requests/second, 3782.88 ns/request
|
||||
//! Scrape handler: 461 530 requests/second, 2169.41 ns/request
|
||||
//! ```
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue