0.34.6_repo_cleanup
This commit is contained in:
1 parent
ce1a90397c
commit
133d2f0f91
273 files changed
+5969
-6926
No files matched your search
Vendored
+28
-20
@@ -1,14 +1,12 @@
|
||||
// Lock-free read path for bounded, per-domain cache dashboard counters.
|
||||
//
|
||||
// Cache-disabled proxy requests still contribute to BYPASS and reason totals,
|
||||
// but must never lock the HOT object/LRU store. Published domain/reason indexes
|
||||
// are immutable; individual counters are atomics. Only first sight of a new
|
||||
// domain/reason acquires the registration mutex.
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
|
||||
const DOMAIN_STATS_LIMIT: usize = 4096;
|
||||
const FAST_REASONS: [&str; 4] = ["cache_disabled", "cache_hit", "cache_miss", "request_cookie"];
|
||||
const FAST_REASONS: [&str; 4] = [
|
||||
"cache_disabled",
|
||||
"cache_hit",
|
||||
"cache_miss",
|
||||
"request_cookie",
|
||||
];
|
||||
|
||||
type ReasonIndex = BTreeMap<&'static str, Arc<AtomicU64>>;
|
||||
type DomainIndex = BTreeMap<String, BTreeMap<String, Arc<DomainStats>>>;
|
||||
@@ -51,13 +49,12 @@ impl DomainStats {
|
||||
"HIT" => &self.hits,
|
||||
"MISS" => &self.misses,
|
||||
_ => &self.bypasses,
|
||||
}.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
self.record_reason(reason);
|
||||
}
|
||||
|
||||
fn record_reason(&self, reason: &'static str) {
|
||||
// Cache OFF is the highest-volume case; avoid reason map lookup and
|
||||
// any shared lock/allocator activity for its dashboard reason.
|
||||
if reason == "cache_disabled" {
|
||||
self.fast_reasons[0].fetch_add(1, Ordering::Relaxed);
|
||||
return;
|
||||
@@ -72,7 +69,10 @@ impl DomainStats {
|
||||
return;
|
||||
}
|
||||
drop(published);
|
||||
let _guard = self.register_reason.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _guard = self
|
||||
.register_reason
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
let published = self.reasons.load_full();
|
||||
if let Some(counter) = published.get(reason) {
|
||||
counter.fetch_add(1, Ordering::Relaxed);
|
||||
@@ -123,16 +123,22 @@ impl Default for DomainStatsStore {
|
||||
impl DomainStatsStore {
|
||||
fn with(&self, scope: &str, domain: &str, action: impl FnOnce(&DomainStats)) {
|
||||
let published = self.domains.load();
|
||||
if let Some(counters) = published.index.get(scope).and_then(|hosts| hosts.get(domain)) {
|
||||
if let Some(counters) = published
|
||||
.index
|
||||
.get(scope)
|
||||
.and_then(|hosts| hosts.get(domain))
|
||||
{
|
||||
action(counters);
|
||||
return;
|
||||
}
|
||||
drop(published);
|
||||
// Rare path: register only 4096 distinct (scope, domain) pairs. The
|
||||
// published map is cloned on first insertion, never on a request hit.
|
||||
let _guard = self.register.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let published = self.domains.load_full();
|
||||
if let Some(counters) = published.index.get(scope).and_then(|hosts| hosts.get(domain)) {
|
||||
if let Some(counters) = published
|
||||
.index
|
||||
.get(scope)
|
||||
.and_then(|hosts| hosts.get(domain))
|
||||
{
|
||||
action(counters);
|
||||
return;
|
||||
}
|
||||
@@ -141,7 +147,9 @@ impl DomainStatsStore {
|
||||
}
|
||||
let mut next = (*published).clone();
|
||||
let counters = Arc::new(DomainStats::default());
|
||||
next.index.entry(scope.to_owned()).or_default()
|
||||
next.index
|
||||
.entry(scope.to_owned())
|
||||
.or_default()
|
||||
.insert(domain.to_owned(), Arc::clone(&counters));
|
||||
next.count += 1;
|
||||
self.domains.store(Arc::new(next));
|
||||
@@ -163,10 +171,10 @@ impl DomainStatsStore {
|
||||
}
|
||||
|
||||
fn saved_body_hit(&self, scope: &str, domain: &str, bytes: usize) {
|
||||
// COLD entries loaded from persisted metadata may be served before a
|
||||
// domain is registered. Preserve first-hit byte accounting as well.
|
||||
self.with(scope, domain, |counters| {
|
||||
counters.saved_body_bytes.fetch_add(bytes as u64, Ordering::Relaxed);
|
||||
counters
|
||||
.saved_body_bytes
|
||||
.fetch_add(bytes as u64, Ordering::Relaxed);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user