udp: avoid Ordering::SeqCst for atomic operations

This commit is contained in:
Joakim Frostegård 2021-11-19 12:30:05 +01:00
parent 2c336793b1
commit a1243c59d6
3 changed files with 15 additions and 13 deletions

View file

@ -132,8 +132,10 @@ pub fn run_request_worker(
let peers_ipv4 = torrents.ipv4.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_ipv6[worker_index.0].store(peers_ipv6, Ordering::SeqCst);
state.statistics.peers_ipv4[worker_index.0]
.store(peers_ipv4, Ordering::Release);
state.statistics.peers_ipv6[worker_index.0]
.store(peers_ipv6, Ordering::Release);
}
last_cleaning = now;
@ -142,9 +144,9 @@ pub fn run_request_worker(
&& now > last_statistics_update + statistics_update_interval
{
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]
.store(torrents.ipv6.len(), Ordering::SeqCst);
.store(torrents.ipv6.len(), Ordering::Release);
last_statistics_update = now;
}

View file

@ -287,11 +287,11 @@ fn read_requests(
state
.statistics
.requests_received
.fetch_add(requests_received, Ordering::SeqCst);
.fetch_add(requests_received, Ordering::Release);
state
.statistics
.bytes_received
.fetch_add(bytes_received, Ordering::SeqCst);
.fetch_add(bytes_received, Ordering::Release);
}
}
@ -451,11 +451,11 @@ fn send_responses(
state
.statistics
.responses_sent
.fetch_add(responses_sent, Ordering::SeqCst);
.fetch_add(responses_sent, Ordering::Release);
state
.statistics
.bytes_sent
.fetch_add(bytes_sent, Ordering::SeqCst);
.fetch_add(bytes_sent, Ordering::Release);
}
}

View file

@ -9,16 +9,16 @@ pub fn gather_and_print_statistics(state: &State, config: &Config) {
let requests_received: f64 = state
.statistics
.requests_received
.fetch_and(0, Ordering::SeqCst) as f64;
.fetch_and(0, Ordering::AcqRel) as f64;
let responses_sent: f64 = state
.statistics
.responses_sent
.fetch_and(0, Ordering::SeqCst) as f64;
.fetch_and(0, Ordering::AcqRel) as f64;
let bytes_received: f64 = state
.statistics
.bytes_received
.fetch_and(0, Ordering::SeqCst) as f64;
let bytes_sent: f64 = state.statistics.bytes_sent.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::AcqRel) as f64;
let requests_per_second = requests_received / 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 {
values.iter().map(|n| n.load(Ordering::SeqCst)).sum()
values.iter().map(|n| n.load(Ordering::Acquire)).sum()
}