Prefer keeps the say at its own POP only, and the direct ranks stop slowing the game day
Review of #205: - Prefer no longer switches the carrier-direct rule off for the whole network. A POP with a Prefer-marked transit port keeps what Prefer says; every other POP keeps the rule. compute(), traceroute and the reference loop in the tests all use the same per-POP rule, and a new test covers it (New York and Chicago, Prefer on one POP's Tell-Ya port). - dayTick() cost. The harness is neutral (the same page on both sides differs by 1%), but the cost was real: the four extra rank passes inside compute()'s main loop made V8 deoptimise compute() 954 times in 30 game days against 46 on main. The direct ranks now run in a small function of their own, in the plain way the reference loop does (their lists are one carrier's ports), so the main loop is the one main has, and the setup moved out of compute(). 61 deopts instead of 954. - Italian: "Porta qui" read as "port here" next to "Porta più vicina"; it is "Instrada qui" now, and "Ogni POP instrada il traffico..." matches. - Help text: says that real BGP carries the traffic from every POP (the shorter AS path beats IGP distance), that Carry here does that here, and that Nearest port is the default. All six languages.
This commit is contained in:
parent
b8845413d3
commit
eb78d7104e
14 changed files with 77 additions and 23 deletions
|
|
@ -5,3 +5,10 @@
|
|||
DIRECT_RANK[tier] = [carries, this POP only]. compute() and traceroute() share this. */
|
||||
const DIRECT_RANK=[null,[2.92,2.93],[2.94,2.95]];
|
||||
const directTier=(carrier,dest)=>carrier===dest?1:(NET[dest].up&&NET[dest].up.includes(carrier))?2:0;
|
||||
// What compute() needs of the rule, built once per call and kept out of compute(), whose size the JIT is sensitive to.
|
||||
// prefc[ci]: 1 where a Prefer-marked transit port has the say, so the rule is off for flows from that POP.
|
||||
// dirOf(id): the carriers you buy from that are direct for network id (itself: tier 1; one of its upstreams: tier 2), or null.
|
||||
function directSetup(E,NC){const cars=new Set(),prefc=new Uint8Array(NC);
|
||||
for(const e of E)if(e.k==='t'){cars.add(e.net);if(e.pref==='high')prefc[e.ci]=1;}
|
||||
const dirOf=id=>{let m=null;if(cars.has(id))(m=new Map()).set(id,1);const up=NET[id].up;if(up)for(const u of up)if(cars.has(u)&&!(m&&m.has(u)))(m||(m=new Map())).set(u,2);return m;};
|
||||
return {prefc,dirOf};}
|
||||
|
|
|
|||
|
|
@ -151,10 +151,10 @@ function compute(){
|
|||
// LOCAL_PREF on an upstream moves it ahead of or behind the other transits, never ahead of peering (#96).
|
||||
const eff=(e,n)=>{let r=base(e,n);if(TR){if(e.k==='t'&&TR.up[e.net])r=TR.up[e.net]==='prefer'?2.9:3.5;if(e.prep)r=4.4;if(e.k!=='c'&&TR.drain.has(e.city))r=4.6;const o=TR.net[n];if(o){if(o.prefer===e.k)r=0.5;else if(o.avoid===e.k)r=4.5;}}return r;};
|
||||
// A carrier's own port for traffic bound for it or for its customers (25-direct-egress.js): tried before plain transit, but
|
||||
// never over RouteScript, a Prefer-marked port or a port set to backup, which all keep the say they had. Such a port is
|
||||
// also an ordinary transit exit (rank 3), so POPs without one of its own can still use it.
|
||||
const hiAny=E.some(e=>e.k==='t'&&e.pref==='high');
|
||||
const dr=(e,n)=>{if(hiAny||e.k!=='t')return 0;const t=directTier(e.net,n);return t&&eff(e,n)===3?DIRECT_RANK[t][e.carry?0:1]:0;};
|
||||
// never over RouteScript or a port set to backup, which keep the say they had, and not from a POP with a Prefer-marked
|
||||
// transit port (PREFC), where Prefer keeps it. Such a port is also an ordinary transit exit (rank 3), so POPs without one of
|
||||
// its own can still use it. DSEL: for each direct rank, the networks that have an exit there.
|
||||
const DIR=directSetup(E,NC),PREFC=DIR.prefc,dirOf=DIR.dirOf,DSEL=new Map();
|
||||
const RANKS=TR?[0,0.5,1,2,CONE_RANK,2.9,2.92,2.93,2.94,2.95,3,3.5,4,4.4,4.5,4.6]:[0,1,2,CONE_RANK,2.92,2.93,2.94,2.95,3,4];
|
||||
// With `protect customers`, business flows take every rank first; home users get what is left.
|
||||
const PASSES=TR&&TR.protect?[x=>x.bz,x=>!x.bz]:null;
|
||||
|
|
@ -164,8 +164,8 @@ function compute(){
|
|||
const idx=L=>{L.hi=L.some(e=>e.hp===0);L.at=new Map();for(const e of L){const h=L.at.get(e.ci);if(h)h.push(e);else L.at.set(e.ci,[e]);}};
|
||||
// Networks with the same exits at a rank share one list (LIST, by content), so what one flow learns serves them all.
|
||||
const LIST=new Map();for(let i=0;i<E.length;i++)E[i].xi=i;
|
||||
const byRank={},RSET=new Set();for(const id of NET_IDS){const m=byRank[id]={};for(const e of okBy[id]){const r=TR?eff(e,id):base(e,id);RSET.add(r);(m[r]||(m[r]=[])).push(e);
|
||||
const d=dr(e,id);if(d){RSET.add(d);(m[d]||(m[d]=[])).push(e);}}
|
||||
const byRank={},RSET=new Set();for(let j=0;j<NET_IDS.length;j++){const id=NET_IDS[j],m=byRank[id]={},dm=dirOf(id);for(const e of okBy[id]){const r=TR?eff(e,id):base(e,id);RSET.add(r);(m[r]||(m[r]=[])).push(e);
|
||||
if(dm&&r===3&&e.k==='t'){const t=dm.get(e.net);if(t){const d=DIRECT_RANK[t][e.carry?0:1];let ds=DSEL.get(d);if(!ds)DSEL.set(d,ds=new Uint8Array(NET_IDS.length));ds[j]=1;RSET.add(d);(m[d]||(m[d]=[])).push(e);}}}
|
||||
for(const r in m){const L=m[r],key=L.map(e=>e.xi).join(','),o=LIST.get(key);if(o){m[r]=o;continue;}
|
||||
let V=L;if(NCOMP>1){const cs=[];for(const e of L){const k=COMP[e.ci];if(k>=0)(cs[k]||(cs[k]=[])).push(e);}for(const s of cs)if(s)idx(s);V={cs};}else idx(L);LIST.set(key,V);m[r]=V;}}
|
||||
// The flow being routed, and from its POP: distances, arriving edges and the paths walked so far, by city index.
|
||||
|
|
@ -215,16 +215,28 @@ function compute(){
|
|||
// Stable, in place: short lists by insertion (no garbage), long ones by the built-in sort. Both are stable with the
|
||||
// same comparison, so the order is the same either way.
|
||||
const sortD=a=>{const n=a.length;if(n>24){a.sort(byDist);return;}for(let i=1;i<n;i++){const x=a[i];let j=i-1;while(j>=0&&byDist(a[j],x)>0){a[j+1]=a[j];j--;}a[j+1]=x;}};
|
||||
// The direct ranks (25-direct-egress.js) have short lists, one carrier's ports, so they take the plain way: the usable exits
|
||||
// nearest first, tried in groups of equal distance, as the reference loop in the tests does. A direct rank only concerns the
|
||||
// networks that have an exit there, and nothing from a POP where Prefer has the say; a port that is not set to carry only takes
|
||||
// its own POP's traffic. Kept in a function of its own so the loop below stays as it was: the JIT is sensitive to its shape.
|
||||
const directPass=(rank,pass)=>{const DS=DSEL.get(rank),LOC=rank===DIRECT_RANK[1][1]||rank===DIRECT_RANK[2][1];
|
||||
for(let fi=0,FN=flows.length;fi<FN;fi++){f=flows[fi];
|
||||
if(f.rem<=1e-6||DS[f.nj]===0||PREFC[f.ci]===1||(pass&&!pass(f)))continue;
|
||||
Dv=SDi[f.ci];Pv=SPi[f.ci];PP=walked[f.ci]||(walked[f.ci]=[]);vis++;
|
||||
let lst=byRank[f.n][rank];if(!lst)continue;if(lst.cs){lst=lst.cs[COMP[f.ci]];if(!lst)continue;}
|
||||
REST.length=0;
|
||||
if(LOC){const here=lst.at.get(f.ci);if(!here)continue;for(let h=0;h<here.length;h++)if(usable(here[h]))REST.push(here[h]);}
|
||||
else for(let li=0;li<lst.length;li++)if(usable(lst[li]))REST.push(lst[li]);
|
||||
sortD(REST);
|
||||
for(let i=0;i<REST.length&&f.rem>1e-6;){let j=i+1;while(j<REST.length&&REST[j].hp===REST[i].hp&&Math.abs(Dv[REST[j].ci]-Dv[REST[i].ci])<1e-6)j++;sendGroup(REST,i,j);i=j;}}};
|
||||
for(const pass of PASSES||[null])for(const rank of RANKS){
|
||||
if(!RSET.has(rank))continue;
|
||||
// A carrier's own port that is not set to carry only takes the traffic of the POP it sits in.
|
||||
const LOC=rank===DIRECT_RANK[1][1]||rank===DIRECT_RANK[2][1];
|
||||
if(DSEL.has(rank)){directPass(rank,pass);continue;}
|
||||
// Index loops in here: plain for…of allocates an iterator per loop until V8 has optimised compute().
|
||||
for(let fi=0,FN=flows.length;fi<FN;fi++){f=flows[fi];
|
||||
if(f.rem<=1e-6||(rank===0&&!f.cache)||(pass&&!pass(f)))continue;
|
||||
Dv=SDi[f.ci];Pv=SPi[f.ci];PP=walked[f.ci]||(walked[f.ci]=[]);vis++;
|
||||
let lst=byRank[f.n][rank];if(!lst)continue;if(lst.cs){lst=lst.cs[COMP[f.ci]];if(!lst)continue;}
|
||||
if(LOC){G.length=0;const here=lst.at.get(f.ci);if(!here)continue;for(let h=0;h<here.length;h++){const e=here[h];if(e.used<e.cap&&!gone(e))G.push(e);}if(G.length)sendGroup(G,0,G.length);continue;}
|
||||
/* Groups are tried nearest first, preferred exits before the rest, in the order a stable sort of the usable
|
||||
exits gives. Exits only fill up once tried, so the usable ones stay the same until then. Nearly every flow
|
||||
fits in its first group: find that one with a scan (nothing is visited yet), and sort only what is left
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue