Performance changes
This commit is contained in:
parent
a9c8dae84b
commit
e805992bb1
1 changed files with 7 additions and 7 deletions
14
src/lib.rs
14
src/lib.rs
|
@ -6,7 +6,7 @@ use std::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
use nanorand::Rng;
|
||||||
use rustls::sign::CertifiedKey;
|
use rustls::sign::CertifiedKey;
|
||||||
|
|
||||||
/// Create a new resolver channel. The Sender can update the key, and the Receiver can be
|
/// Create a new resolver channel. The Sender can update the key, and the Receiver can be
|
||||||
|
@ -64,11 +64,11 @@ impl sealed::Shard {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&self, key: CertifiedKey) {
|
fn update(&self, key: CertifiedKey) {
|
||||||
let mut guard = self.lock.write().unwrap();
|
{
|
||||||
// update generation while lock is held - ensures any "after" accesses to generation queue
|
*self.lock.write().unwrap() = Arc::new(key);
|
||||||
// at the read-lock for a new key
|
}
|
||||||
self.generation.fetch_add(1, Ordering::Release);
|
// update generation after lock is released. reduces lock contention with readers
|
||||||
*guard = Arc::new(key);
|
self.generation.fetch_add(1, Ordering::AcqRel);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read(&self) -> Arc<CertifiedKey> {
|
fn read(&self) -> Arc<CertifiedKey> {
|
||||||
|
@ -124,7 +124,7 @@ impl<const SHARDS: usize> ChannelResolver<SHARDS> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn read(&self) -> Arc<CertifiedKey> {
|
pub fn read(&self) -> Arc<CertifiedKey> {
|
||||||
// choose random shard to reduce contention. unwrap since slice is always non-empty
|
// choose random shard to reduce contention. unwrap since slice is always non-empty
|
||||||
self.locks.choose(&mut thread_rng()).unwrap().read()
|
self.locks[nanorand::tls_rng().generate_range(0..SHARDS)].read()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue