Adapt import commit batches from observed transaction duration

This commit is contained in:
2026-11-10 01:10:05 +08:00
parent 40f3c97bbd
commit 2529a801b2
5 changed files with 45 additions and 4 deletions
+15
View File
@@ -0,0 +1,15 @@
/** Runner-owned feedback, not persisted job state. Probe bounded batches to
* distinguish fixed publication cost from the marginal cost of another unit. */
export function createImportBatches(budget:number,max:number){
let limit=1,observed=false;
return Object.freeze({
get limit(){return limit;},
get observed(){return observed;},
record(units:number,elapsed:number){
observed=true;
if(elapsed>budget){limit=Math.max(1,Math.min(limit-1,Math.floor(units*budget/elapsed)));return;}
// A short tail/dependency group does not prove that a larger batch is cheap.
if(units>=limit)limit=Math.min(max,limit+Math.max(1,Math.floor(limit/2)));
},
});
}