v0.34.0_12
This commit is contained in:
1 parent
9f20d5195e
commit
929854898f
16 files changed
+186
-285
No files matched your search
+1
-11
@@ -1,15 +1,5 @@
|
||||
use serde::Serialize;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
/// Isolate a high-contention counter without spreading every request-level
|
||||
/// atomic across a separate cache line. Existing read/write API is unchanged.
|
||||
#[repr(align(64))]
|
||||
#[derive(Default, Debug)]
|
||||
pub struct CacheAlignedAtomicU64(AtomicU64);
|
||||
impl std::ops::Deref for CacheAlignedAtomicU64 {
|
||||
type Target = AtomicU64;
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Metrics {
|
||||
pub admin_requests: AtomicU64,
|
||||
@@ -45,7 +35,7 @@ pub struct Metrics {
|
||||
pub websocket_bytes_in: AtomicU64,
|
||||
pub websocket_bytes_out: AtomicU64,
|
||||
pub websocket_duration_us: AtomicU64,
|
||||
pub requests: CacheAlignedAtomicU64,
|
||||
pub requests: AtomicU64,
|
||||
pub completed: AtomicU64,
|
||||
pub active: AtomicU64,
|
||||
pub errors: AtomicU64,
|
||||
|
||||
@@ -8,7 +8,7 @@ pub struct VhostMetrics {
|
||||
pub bytes_in: AtomicU64,
|
||||
pub bytes_out: AtomicU64,
|
||||
pub duration_us: AtomicU64,
|
||||
pub ewma_duration_us: CacheAlignedAtomicU64,
|
||||
pub ewma_duration_us: AtomicU64,
|
||||
pub status: [AtomicU64; 5],
|
||||
pub buckets: [AtomicU64; 11],
|
||||
}
|
||||
|
||||
@@ -63,18 +63,4 @@ mod compression_counter_tests {
|
||||
assert_eq!(view.compression_zstd, 1);
|
||||
assert_eq!(view.compression_deflate, 1);
|
||||
}
|
||||
#[test]
|
||||
fn cache_aligned_counters_keep_exact_values_and_separate_hot_lines() {
|
||||
let m = VhostMetrics::default();
|
||||
let ewma = &m.ewma_duration_us as *const _ as usize;
|
||||
assert_eq!(ewma % 64, 0);
|
||||
m.active.fetch_add(1, Ordering::Relaxed);
|
||||
m.requests.fetch_add(1, Ordering::Relaxed);
|
||||
m.complete(200, false, std::time::Duration::from_micros(100), 20, 1040);
|
||||
assert_eq!(n(&m.completed), 1);
|
||||
assert_eq!(n(&m.active), 0);
|
||||
assert_eq!(n(&m.requests), 1);
|
||||
assert_eq!(n(&m.bytes_out), 1040);
|
||||
assert_eq!(n(&m.ewma_duration_us), 100);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user