Free caches scale with demand: more boxes once one per site is not enough (closes #248)

This commit is contained in:
Frederic Jung 2026-10-31 15:57:46 +01:00
parent 20c70f16e6
commit f0d0675bad
No known key found for this signature in database
3 changed files with 22 additions and 3 deletions

View file

@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows
## [Unreleased]
- The intern's Accept free caches order, and the Request caches button, now add more cache boxes as demand to a network outgrows the ones you have (#248). Before, they stopped at one box per site.
- Manila gets real exchanges: GotchaFIX Manila, the free community Bayanihan-IX and In-Vitro-IX, run by PLDTea Time. Diverge, Smarty Pants, Ditto and RISE & Shine join as Philippine networks, and PLDTea Time and Globe-Trotter Telecom now sell transit.
- Cebu joins the map on its own island, with GotchaFIX Cebu and two domestic cables from Manila: the Pan de Sal Cable Network and the Philippines Long Distance Relationship. PLDTea Time, Globe-Trotter Telecom, Diverge and RISE & Shine reach Cebu, and typhoons can hit it too.
- Davao joins the map on Mindanao, with GotchaFIX Davao. Bi-Frosted and SEA-US Later now land in Davao, as the real cables do, instead of Manila; a link you already run on their old Manila landings keeps working as a plain subsea link. Three domestic cables reach Davao from Cebu: the Pan de Sal Cable Network, the Philippines Long Distance Relationship and the new Diverge VisMin Express. RISE & Shine peers at GotchaFIX Davao. The Pan de Sal Cable Network also runs straight from Manila to Davao.

View file

@ -10,9 +10,13 @@ function utilityCacheMoves(city){if(!S||!S.pops[city])return [];const groups=new
const from=diff>0?'a':'b',to=from==='a'?'b':'a';let left=Math.floor(Math.abs(diff)/2);
for(const g of groups.values())if(left&&g[from].length>g[to].length){move(g,from,1);left--;}
return moves;}
function utilityCaches(city){const p=S&&S.pops[city];if(!p)return null;const sites=p.site2?['a','b']:['a'],add=[],have=new Set();
for(const c of S.caches)if(c.city===city)have.add(c.net+'@'+(c.site==='b'?'b':'a'));
for(const n of NETS)if(n.cache&&(R.demTo[n.id]||0)>=n.cache.min)for(const site of sites)if(!have.has(n.id+'@'+site))add.push({net:n.id,site});
// One box per site first; then more boxes while this city's demand to the network outgrows them (100G each, #248).
function utilityCaches(city){const p=S&&S.pops[city];if(!p)return null;const sites=p.site2?['a','b']:['a'],add=[],have={};
for(const c of S.caches)if(c.city===city){const k=c.net+'@'+(c.site==='b'?'b':'a');have[k]=(have[k]||0)+1;}
for(const n of NETS)if(n.cache&&(R.demTo[n.id]||0)>=n.cache.min){const box=sites.map(st=>have[n.id+'@'+st]||0);
sites.forEach((site,i)=>{if(!box[i]){add.push({net:n.id,site});box[i]=1;}});
const need=Math.ceil(((R.cityDem&&R.cityDem[city])||0)*(NSH[n.id]||0)/CACHE_CAP-1e-9);
for(let t=box.reduce((a,b)=>a+b,0);t<need;t++){const i=box.indexOf(Math.min(...box));add.push({net:n.id,site:sites[i]});box[i]++;}}
return {add,key:add.map(c=>c.net+'@'+c.site).join(','),mo:add.length*CACHE_MO,free:Math.max(0,portsMax(city)-portsUsed(city))};}
function utilityKit(city){const p=S&&S.pops[city];if(!p)return null;
const gen=!p.gen,site=!p.site2,router=(p.routers||1)<2,g=p.rgen||0;

View file

@ -118,3 +118,17 @@ test('balanced caches keep serving when either site fails', t => {
}
assert.deepEqual(errors, []);
});
test('more boxes while demand outgrows them, balanced across sites (#248)', t => {
const { ev, errors } = setup(t);
ev("Object.assign(S.pops.fra,{site2:true,routers:2});S.caches=[{id:'a1',city:'fra',net:'cfl',site:'a'},{id:'b1',city:'fra',net:'cfl',site:'b'}];compute();R.demTo={cfl:NET.cfl.cache.min};R.cityDem.fra=450/NSH.cfl");
const add = JSON.parse(ev("JSON.stringify(utilityCaches('fra').add)"));
assert.deepEqual(add.map(x => x.net + '@' + x.site), ['cfl@a', 'cfl@b', 'cfl@a'], '450G needs five 100G boxes: three more, spread over both sites');
ev("R.cityDem.fra=150/NSH.cfl");
assert.equal(ev("utilityCaches('fra').add.length"), 0, 'two boxes already carry 150G');
// Requesting them adds just what is missing.
ev("R.cityDem.fra=350/NSH.cfl");
ev("ACT.utilityCaches({city:'fra',quote:utilityCaches('fra').key})");
assert.equal(ev("S.caches.filter(c=>c.net==='cfl').length"), 4);
assert.deepEqual(errors, []);
});