fix: cache calculation

This commit is contained in:
2026-04-15 17:31:39 +08:00
parent 365ceac3be
commit ff316c6873
23 changed files with 500 additions and 336 deletions

View File

@@ -1,6 +1,6 @@
use crate::cluster::meta_store::MetaStore;
use crate::instance::Instance;
use crate::router::{CandidateInfo, RouteDecision, Router};
use crate::router::{local_l0_scores, CandidateInfo, RouteDecision, Router};
use crate::trace::RequestRecord;
pub struct TtlAwareRouter {
@@ -22,18 +22,17 @@ impl Router for TtlAwareRouter {
&mut self,
req: &RequestRecord,
instances: &[Instance],
meta: &MetaStore,
now: f64,
_meta: &MetaStore,
_now: f64,
) -> RouteDecision {
let n = instances.len();
let scores = meta.score_prefix(&req.hash_ids, now, n);
let scores = local_l0_scores(req, instances);
let mut best = 0u32;
let mut best_key = (i64::MIN, f64::INFINITY); // maximize prefix, then minimize load
let mut candidates = Vec::with_capacity(n);
for inst in instances {
let p = scores[inst.id as usize];
let load = inst.kv_blocks_used as f64
+ self.alpha * inst.queue_len() as f64;
let load = inst.kv_blocks_used as f64 + self.alpha * inst.queue_len() as f64;
candidates.push(CandidateInfo {
instance: inst.id,
predicted_prefix: p,
@@ -53,7 +52,7 @@ impl Router for TtlAwareRouter {
chosen: best,
probe_overhead_s: 0.0,
candidates,
reason: "max meta_store prefix, tie -> least loaded",
reason: "max local L0 prefix, tie -> least loaded",
}
}
}