v0.34.0_2
This commit is contained in:
1 parent
0a8bc6f040
commit
434e789144
38 files changed
+899
-238
No files matched your search
Vendored
+20
-32
@@ -111,7 +111,7 @@ struct Entry {
|
||||
target: String,
|
||||
tags: Vec<String>,
|
||||
created_at: SystemTime,
|
||||
headers: HeaderMap,
|
||||
headers: Arc<HeaderMap>,
|
||||
body: Bytes,
|
||||
/// Backing allocation retained by `body`; can exceed `body.len()`.
|
||||
body_allocated: usize,
|
||||
@@ -181,6 +181,9 @@ fn hot_entry_cost(
|
||||
.sum::<usize>();
|
||||
body_allocated
|
||||
.saturating_add(std::mem::size_of::<Entry>())
|
||||
// Arc<HeaderMap> owns the actual map on a separate allocation.
|
||||
.saturating_add(std::mem::size_of::<HeaderMap>())
|
||||
.saturating_add(2 * std::mem::size_of::<usize>())
|
||||
.saturating_add(index_heap)
|
||||
.saturating_add(header_heap)
|
||||
.saturating_add(string_vec_heap(vary))
|
||||
@@ -333,8 +336,8 @@ struct Store {
|
||||
control_revision: u64,
|
||||
scope_generations: HashMap<String, u64>,
|
||||
key_generations: HashMap<Key, u64>,
|
||||
domains: BTreeMap<(String, String), DomainCounters>,
|
||||
last_sweep: Option<Instant>,
|
||||
domains: BTreeMap<String, BTreeMap<String, DomainCounters>>,
|
||||
domain_count: usize,
|
||||
}
|
||||
impl Store {
|
||||
fn index_variant(&mut self, base_key: Key, key: Key) {
|
||||
@@ -360,39 +363,24 @@ impl Store {
|
||||
Some(entry)
|
||||
}
|
||||
fn domain(&mut self, scope: &str, domain: &str) -> Option<&mut DomainCounters> {
|
||||
let key = (scope.to_owned(), domain.to_owned());
|
||||
// Cardinality is bounded independently of resident cache capacity.
|
||||
if self.domains.len() >= 4096 && !self.domains.contains_key(&key) {
|
||||
// The common path is a borrowed lookup: no allocation of scope/domain
|
||||
// strings for every cache hit or log-reason counter update.
|
||||
if self.domains.get(scope).is_some_and(|d| d.contains_key(domain)) {
|
||||
return self.domains.get_mut(scope)?.get_mut(domain);
|
||||
}
|
||||
if self.domain_count >= 4096 {
|
||||
return None;
|
||||
}
|
||||
Some(self.domains.entry(key).or_default())
|
||||
self.domain_count += 1;
|
||||
Some(self.domains.entry(scope.to_owned()).or_default()
|
||||
.entry(domain.to_owned()).or_default())
|
||||
}
|
||||
fn sweep(&mut self) -> usize {
|
||||
if self
|
||||
.last_sweep
|
||||
.is_some_and(|v| v.elapsed() < Duration::from_secs(1))
|
||||
{
|
||||
return 0;
|
||||
fn saved_body_hit(&mut self, scope: &str, domain: &str, bytes: usize) {
|
||||
// Every admitted HOT insertion registered its domain. If the bounded
|
||||
// stats table is full, skip accounting for an unregistered domain.
|
||||
if let Some(c) = self.domains.get_mut(scope).and_then(|d| d.get_mut(domain)) {
|
||||
c.saved_body_bytes = c.saved_body_bytes.saturating_add(bytes as u64);
|
||||
}
|
||||
self.last_sweep = Some(Instant::now());
|
||||
let stale: Vec<_> = self
|
||||
.entries
|
||||
.iter()
|
||||
.filter(|(_, e)| {
|
||||
let age = e.initial_age.saturating_add(e.received.elapsed()).as_secs();
|
||||
age >= retention_deadline(
|
||||
e.ttl,
|
||||
e.stale_while_revalidate,
|
||||
e.stale_if_error,
|
||||
e.origin_etag.is_some() || e.origin_last_modified.is_some(),
|
||||
)
|
||||
})
|
||||
.map(|(k, _)| *k)
|
||||
.collect();
|
||||
for key in &stale {
|
||||
self.remove(key);
|
||||
}
|
||||
stale.len()
|
||||
}
|
||||
fn next_sequence(&mut self) -> u64 {
|
||||
// No practical wrapping, but a wrap must not corrupt LRU bookkeeping.
|
||||
|
||||
Vendored
+4
@@ -73,6 +73,7 @@ pub struct Cache {
|
||||
fill_flight_sequence: AtomicU64,
|
||||
collapse_waiters: AtomicU64,
|
||||
bans: Mutex<Vec<BanRule>>,
|
||||
ban_rule_count: AtomicU64,
|
||||
ban_sequence: AtomicU64,
|
||||
proactive_scheduled_keys: Mutex<HashSet<Key>>,
|
||||
proactive_inflight: AtomicU64,
|
||||
@@ -347,6 +348,9 @@ fn hot_resident_age(entry: &Entry) -> Duration {
|
||||
}
|
||||
|
||||
fn matching_hot_key(store: &Store, ticket: &Ticket) -> Option<Key> {
|
||||
if store.entries.get(&ticket.key).is_some_and(|entry| entry.vary.is_empty()) {
|
||||
return Some(ticket.key);
|
||||
}
|
||||
store
|
||||
.variants
|
||||
.get(&ticket.key)?
|
||||
|
||||
Reference in new issue
Block a user