mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
udp: avoid Ordering::SeqCst for atomic operations
This commit is contained in:
parent
2c336793b1
commit
a1243c59d6
3 changed files with 15 additions and 13 deletions
|
|
@ -132,8 +132,10 @@ pub fn run_request_worker(
|
||||||
let peers_ipv4 = torrents.ipv4.values().map(|t| t.peers.len()).sum();
|
let peers_ipv4 = torrents.ipv4.values().map(|t| t.peers.len()).sum();
|
||||||
let peers_ipv6 = torrents.ipv6.values().map(|t| t.peers.len()).sum();
|
let peers_ipv6 = torrents.ipv6.values().map(|t| t.peers.len()).sum();
|
||||||
|
|
||||||
state.statistics.peers_ipv4[worker_index.0].store(peers_ipv4, Ordering::SeqCst);
|
state.statistics.peers_ipv4[worker_index.0]
|
||||||
state.statistics.peers_ipv6[worker_index.0].store(peers_ipv6, Ordering::SeqCst);
|
.store(peers_ipv4, Ordering::Release);
|
||||||
|
state.statistics.peers_ipv6[worker_index.0]
|
||||||
|
.store(peers_ipv6, Ordering::Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_cleaning = now;
|
last_cleaning = now;
|
||||||
|
|
@ -142,9 +144,9 @@ pub fn run_request_worker(
|
||||||
&& now > last_statistics_update + statistics_update_interval
|
&& now > last_statistics_update + statistics_update_interval
|
||||||
{
|
{
|
||||||
state.statistics.torrents_ipv4[worker_index.0]
|
state.statistics.torrents_ipv4[worker_index.0]
|
||||||
.store(torrents.ipv4.len(), Ordering::SeqCst);
|
.store(torrents.ipv4.len(), Ordering::Release);
|
||||||
state.statistics.torrents_ipv6[worker_index.0]
|
state.statistics.torrents_ipv6[worker_index.0]
|
||||||
.store(torrents.ipv6.len(), Ordering::SeqCst);
|
.store(torrents.ipv6.len(), Ordering::Release);
|
||||||
|
|
||||||
last_statistics_update = now;
|
last_statistics_update = now;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -287,11 +287,11 @@ fn read_requests(
|
||||||
state
|
state
|
||||||
.statistics
|
.statistics
|
||||||
.requests_received
|
.requests_received
|
||||||
.fetch_add(requests_received, Ordering::SeqCst);
|
.fetch_add(requests_received, Ordering::Release);
|
||||||
state
|
state
|
||||||
.statistics
|
.statistics
|
||||||
.bytes_received
|
.bytes_received
|
||||||
.fetch_add(bytes_received, Ordering::SeqCst);
|
.fetch_add(bytes_received, Ordering::Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -451,11 +451,11 @@ fn send_responses(
|
||||||
state
|
state
|
||||||
.statistics
|
.statistics
|
||||||
.responses_sent
|
.responses_sent
|
||||||
.fetch_add(responses_sent, Ordering::SeqCst);
|
.fetch_add(responses_sent, Ordering::Release);
|
||||||
state
|
state
|
||||||
.statistics
|
.statistics
|
||||||
.bytes_sent
|
.bytes_sent
|
||||||
.fetch_add(bytes_sent, Ordering::SeqCst);
|
.fetch_add(bytes_sent, Ordering::Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,16 @@ pub fn gather_and_print_statistics(state: &State, config: &Config) {
|
||||||
let requests_received: f64 = state
|
let requests_received: f64 = state
|
||||||
.statistics
|
.statistics
|
||||||
.requests_received
|
.requests_received
|
||||||
.fetch_and(0, Ordering::SeqCst) as f64;
|
.fetch_and(0, Ordering::AcqRel) as f64;
|
||||||
let responses_sent: f64 = state
|
let responses_sent: f64 = state
|
||||||
.statistics
|
.statistics
|
||||||
.responses_sent
|
.responses_sent
|
||||||
.fetch_and(0, Ordering::SeqCst) as f64;
|
.fetch_and(0, Ordering::AcqRel) as f64;
|
||||||
let bytes_received: f64 = state
|
let bytes_received: f64 = state
|
||||||
.statistics
|
.statistics
|
||||||
.bytes_received
|
.bytes_received
|
||||||
.fetch_and(0, Ordering::SeqCst) as f64;
|
.fetch_and(0, Ordering::AcqRel) as f64;
|
||||||
let bytes_sent: f64 = state.statistics.bytes_sent.fetch_and(0, Ordering::SeqCst) as f64;
|
let bytes_sent: f64 = state.statistics.bytes_sent.fetch_and(0, Ordering::AcqRel) as f64;
|
||||||
|
|
||||||
let requests_per_second = requests_received / interval as f64;
|
let requests_per_second = requests_received / interval as f64;
|
||||||
let responses_per_second: f64 = responses_sent / interval as f64;
|
let responses_per_second: f64 = responses_sent / interval as f64;
|
||||||
|
|
@ -58,5 +58,5 @@ pub fn gather_and_print_statistics(state: &State, config: &Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sum_atomic_usizes(values: &[AtomicUsize]) -> usize {
|
fn sum_atomic_usizes(values: &[AtomicUsize]) -> usize {
|
||||||
values.iter().map(|n| n.load(Ordering::SeqCst)).sum()
|
values.iter().map(|n| n.load(Ordering::Acquire)).sum()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue