pub struct TlsCounter { /* private fields */ }Expand description
Sharded atomic counter optimized for concurrent access from multiple threads.
Uses cache-line-padded shards to prevent false sharing. Each thread is assigned a shard index, so updates from different threads typically hit different cache lines.
This design handles interleaved access to multiple counters efficiently - unlike a single-slot cache approach, there’s no “cache thrashing” when alternating between counters.
§Memory
Each counter uses NUM_SHARDS × 128 bytes = 8KB (with 64 shards). This is larger than a simple AtomicU64 but virtually eliminates contention.
Implementations§
Trait Implementations§
Source§impl Debug for TlsCounter
impl Debug for TlsCounter
Auto Trait Implementations§
impl !Freeze for TlsCounter
impl RefUnwindSafe for TlsCounter
impl Send for TlsCounter
impl Sync for TlsCounter
impl Unpin for TlsCounter
impl UnsafeUnpin for TlsCounter
impl UnwindSafe for TlsCounter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request