MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / make_governor_at

Function make_governor_at

nodedb/src/data/executor/core_loop/pressure.rs:187–208  ·  view source on GitHub ↗

Build a governor with every engine having `budget_bytes`, then pre-fill `engine` to `utilization_percent`.

(engine: EngineId, utilization_percent: u8)

Source from the content-addressed store, hash-verified

185 /// Build a governor with every engine having `budget_bytes`, then
186 /// pre-fill `engine` to `utilization_percent`.
187 fn make_governor_at(engine: EngineId, utilization_percent: u8) -> Arc<MemoryGovernor> {
188 let budget_bytes: usize = 10_000;
189 let mut engine_limits = HashMap::new();
190 for id in EngineId::ALL {
191 engine_limits.insert(*id, budget_bytes);
192 }
193 let global_ceiling = budget_bytes * EngineId::ALL.len() * 2;
194 let gov = MemoryGovernor::new(GovernorConfig {
195 global_ceiling,
196 engine_limits,
197 })
198 .unwrap();
199 let fill = (budget_bytes as u64 * utilization_percent as u64 / 100) as usize;
200 if fill > 0 {
201 // Intentionally leak the token so the engine budget stays allocated
202 // for the lifetime of the test governor. Test-only pattern.
203 if let Ok(tok) = gov.try_reserve(DatabaseId::DEFAULT, TenantId::new(1), engine, fill) {
204 std::mem::forget(tok);
205 }
206 }
207 Arc::new(gov)
208 }
209
210 fn make_task() -> ExecutionTask {
211 ExecutionTask::new(Request {

Calls 3

insertMethod · 0.45
lenMethod · 0.45
try_reserveMethod · 0.45