1010 * tenants always have capacity and any slowdown is the scan's doing.
1111 *
1212 * Worst-case ordering on purpose: the blocked sessions are the oldest and the first to
13- * register, so they lead both the virtual-time scan and the age-ordered scan.
14- * The heavy session registers last but holds the oldest runs outside tenant A, so the
15- * two scans treat it differently and its share shows which one is doing the serving.
13+ * register, so they lead the dequeue's age-ordered scan.
14+ * The heavy session registers last but holds the oldest runs outside tenant A.
1615 *
17- * Reports, per blocked-session count and per dequeue script (virtual-time and age-order) :
16+ * Reports, per blocked-session count:
1817 * calls and seconds to drain the light sessions and everything, calls that served nothing
19- * and the longest such streak, the heavy session's share of the first 20 calls' serves (a
20- * fair scan gives it about one in fifty; age order gives it one per call), client wall
18+ * and the longest such streak, the heavy session's share of the first 20 calls' serves
19+ * ( age order gives it one per call), client wall
2120 * time, and Redis-side script time and command count from `INFO commandstats`.
2221 *
2322 * A second benchmark keeps the light sessions enqueuing fresh runs at a steady rate for the
@@ -83,8 +82,6 @@ const WAKE_SECONDS = Number(process.env.BENCH_WAKE_SECONDS ?? 60);
8382const WAKE_RUN_MS = Number ( process . env . BENCH_WAKE_RUN_MS ?? 500 ) ;
8483const SKIP_AHEAD = process . env . BENCH_GATE_SKIP_AHEAD === "1" ;
8584const POOLS_HOLDERS_SAME = process . env . BENCH_POOLS_HOLDERS === "same" ;
86- /** Skip-ahead applies to the age-order dequeue only, so its runs leave virtual time out. */
87- const SCRIPTS = SKIP_AHEAD ? [ false ] : [ false , true ] ;
8885const POOLS = Number ( process . env . BENCH_POOLS ?? 500 ) ;
8986const STEADY_PARKED = Number ( process . env . BENCH_STEADY_PARKED ?? 10_000 ) ;
9087const OUT_DIR = process . env . BENCH_OUT_DIR ?? join ( process . cwd ( ) , ".." , ".." , ".bench" ) ;
@@ -138,7 +135,7 @@ const env = {
138135 * master-queue consumer per shard, and the dequeue job that every enqueue and
139136 * acknowledgement schedules, debounced and picked up by the queue's own worker.
140137 */
141- function createQueue ( redisContainer : any , vtime : boolean , live = false , meter ?: any ) {
138+ function createQueue ( redisContainer : any , live = false , meter ?: any ) {
142139 const redis = {
143140 keyPrefix : KEY_PREFIX ,
144141 host : redisContainer . getHost ( ) ,
@@ -173,7 +170,6 @@ function createQueue(redisContainer: any, vtime: boolean, live = false, meter?:
173170 concurrency : LIVE . workerConcurrency ,
174171 }
175172 : { disabled : true } ,
176- ckVirtualTimeScheduling : { enabled : vtime } ,
177173 totalConcurrencyEnabled : true ,
178174 gatesEnabled : true ,
179175 gateSkipAhead : { enabled : SKIP_AHEAD } ,
@@ -238,8 +234,8 @@ async function redisSide(queue: any) {
238234 return { scriptUsec, commands } ;
239235}
240236
241- async function runScenario ( redisContainer : any , vtime : boolean , blocked : number , interval : number ) {
242- const queue = createQueue ( redisContainer , vtime ) ;
237+ async function runScenario ( redisContainer : any , blocked : number , interval : number ) {
238+ const queue = createQueue ( redisContainer ) ;
243239 try {
244240 await queue . redis . flushdb ( ) ;
245241 await queue . updateQueueConcurrencyLimits ( env , QUEUE , 50 ) ;
@@ -330,7 +326,6 @@ async function runScenario(redisContainer: any, vtime: boolean, blocked: number,
330326 }
331327
332328 return {
333- script : vtime ? "vtime" : "age-order" ,
334329 skipAhead : SKIP_AHEAD ,
335330 intervalMs : interval ,
336331 blocked,
@@ -355,8 +350,8 @@ async function runScenario(redisContainer: any, vtime: boolean, blocked: number,
355350}
356351
357352/** Tenant A at its gate cap with `blocked` old queued sessions, seeded with nothing polling. */
358- async function seedBlockedTenant ( redisContainer : any , vtime : boolean , blocked : number ) {
359- const queue = createQueue ( redisContainer , vtime ) ;
353+ async function seedBlockedTenant ( redisContainer : any , blocked : number ) {
354+ const queue = createQueue ( redisContainer ) ;
360355 try {
361356 await queue . redis . flushdb ( ) ;
362357 await queue . updateQueueConcurrencyLimits ( env , QUEUE , 50 ) ;
@@ -378,15 +373,10 @@ async function seedBlockedTenant(redisContainer: any, vtime: boolean, blocked: n
378373 }
379374}
380375
381- async function runArrivalScenario (
382- redisContainer : any ,
383- vtime : boolean ,
384- blocked : number ,
385- live : boolean
386- ) {
387- await seedBlockedTenant ( redisContainer , vtime , blocked ) ;
376+ async function runArrivalScenario ( redisContainer : any , blocked : number , live : boolean ) {
377+ await seedBlockedTenant ( redisContainer , blocked ) ;
388378 const dequeues = dequeueCallCounter ( ) ;
389- const queue = createQueue ( redisContainer , vtime , live , dequeues . meter ) ;
379+ const queue = createQueue ( redisContainer , live , dequeues . meter ) ;
390380 try {
391381 const shard = keys . masterQueueShardForEnvironment ( env . id , SHARD_COUNT ) ;
392382
@@ -454,7 +444,6 @@ async function runArrivalScenario(
454444 const all = waits . map ( ( w ) => w . wait ) ;
455445 const scriptCalls = await dequeues . calls ( ) ;
456446 return {
457- script : vtime ? "vtime" : "age-order" ,
458447 skipAhead : SKIP_AHEAD ,
459448 pacing : live ? "live" : `every ${ ARRIVAL_POLL_MS } ms` ,
460449 blocked,
@@ -517,9 +506,9 @@ function dequeueCallCounter() {
517506 * ARRIVAL_RATE and are acknowledged at once. Everything runs on the queue's own machinery
518507 * at LIVE settings.
519508 */
520- async function runWakeScenario ( redisContainer : any , vtime : boolean , blocked : number ) {
509+ async function runWakeScenario ( redisContainer : any , blocked : number ) {
521510 const dequeues = dequeueCallCounter ( ) ;
522- const queue = createQueue ( redisContainer , vtime , true , dequeues . meter ) ;
511+ const queue = createQueue ( redisContainer , true , dequeues . meter ) ;
523512 try {
524513 await queue . redis . flushdb ( ) ;
525514 await queue . updateQueueConcurrencyLimits ( env , QUEUE , 50 ) ;
@@ -635,7 +624,6 @@ async function runWakeScenario(redisContainer: any, vtime: boolean, blocked: num
635624 }
636625 const perSession = [ ...servedPerSession . values ( ) ] ;
637626 return {
638- script : vtime ? "vtime" : "age-order" ,
639627 skipAhead : SKIP_AHEAD ,
640628 blocked,
641629 cappedServedPerSec : round ( cappedServed / WAKE_SECONDS ) ,
@@ -671,8 +659,8 @@ async function runWakeScenario(redisContainer: any, vtime: boolean, blocked: num
671659 * a worker is recorded. Admitted waiters are never acknowledged, so every sample is a slot
672660 * freed from the other queue.
673661 */
674- async function runCrossQueueScenario ( redisContainer : any , vtime : boolean ) {
675- const queue = createQueue ( redisContainer , vtime , true ) ;
662+ async function runCrossQueueScenario ( redisContainer : any ) {
663+ const queue = createQueue ( redisContainer , true ) ;
676664 try {
677665 await queue . redis . flushdb ( ) ;
678666 await queue . updateQueueConcurrencyLimits ( env , QUEUE , 50 ) ;
@@ -708,7 +696,6 @@ async function runCrossQueueScenario(redisContainer: any, vtime: boolean) {
708696 await sleep ( Math . max ( 0 , 7_000 - ( Date . now ( ) - releasedAt ) ) ) ;
709697 }
710698 return {
711- script : vtime ? "vtime" : "age-order" ,
712699 skipAhead : SKIP_AHEAD ,
713700 samples : waits . join ( "," ) ,
714701 waitMinMs : Math . min ( ...waits ) ,
@@ -726,10 +713,10 @@ async function runCrossQueueScenario(redisContainer: any, vtime: boolean) {
726713 * arrive at ARRIVAL_RATE and are acknowledged at once. Script calls and Redis commands
727714 * are sampled over a 60s window after a 30s warm-up.
728715 */
729- async function runSteadyScenario ( redisContainer : any , vtime : boolean ) {
730- await seedBlockedTenant ( redisContainer , vtime , STEADY_PARKED ) ;
716+ async function runSteadyScenario ( redisContainer : any ) {
717+ await seedBlockedTenant ( redisContainer , STEADY_PARKED ) ;
731718 const dequeues = dequeueCallCounter ( ) ;
732- const queue = createQueue ( redisContainer , vtime , true , dequeues . meter ) ;
719+ const queue = createQueue ( redisContainer , true , dequeues . meter ) ;
733720 try {
734721 const enqueuedAt = new Map < string , number > ( ) ;
735722 let waits : number [ ] = [ ] ;
@@ -779,7 +766,6 @@ async function runSteadyScenario(redisContainer: any, vtime: boolean) {
779766 const side = await redisSide ( queue ) ;
780767 const parked = ( await queue . redis . keys ( `${ KEY_PREFIX } *ckHint:*` ) ) . length ;
781768 results . push ( {
782- script : vtime ? "vtime" : "age-order" ,
783769 skipAhead : SKIP_AHEAD ,
784770 window : window . name ,
785771 blocked : STEADY_PARKED ,
@@ -805,9 +791,9 @@ async function runSteadyScenario(redisContainer: any, vtime: boolean) {
805791 * QUEUE. A holder is acknowledged every 100ms, in a scattered order, and the time until
806792 * the waiter behind it is handed to a worker is recorded.
807793 */
808- async function runManyPoolsScenario ( redisContainer : any , vtime : boolean ) {
794+ async function runManyPoolsScenario ( redisContainer : any ) {
809795 const dequeues = dequeueCallCounter ( ) ;
810- const queue = createQueue ( redisContainer , vtime , true , dequeues . meter ) ;
796+ const queue = createQueue ( redisContainer , true , dequeues . meter ) ;
811797 const sessionGate = "limit/session" ;
812798 try {
813799 await queue . redis . flushdb ( ) ;
@@ -885,7 +871,6 @@ async function runManyPoolsScenario(redisContainer: any, vtime: boolean) {
885871 const seconds = ( Date . now ( ) - startedAt ) / 1000 ;
886872 const side = await redisSide ( queue ) ;
887873 return {
888- script : vtime ? "vtime" : "age-order" ,
889874 skipAhead : SKIP_AHEAD ,
890875 pools : POOLS ,
891876 holders : POOLS_HOLDERS_SAME ? "same queue" : "other queue" ,
@@ -907,10 +892,8 @@ describe("run-queue gate-blocked variants benchmark", () => {
907892 redisTest ( "a keyed gate at its cap blocking many variants" , async ( { redisContainer } ) => {
908893 const results : Array < Record < string , number | string | boolean > > = [ ] ;
909894 for ( const interval of INTERVALS ) {
910- for ( const vtime of SCRIPTS ) {
911- for ( const blocked of BLOCKED ) {
912- results . push ( await runScenario ( redisContainer , vtime , blocked , interval ) ) ;
913- }
895+ for ( const blocked of BLOCKED ) {
896+ results . push ( await runScenario ( redisContainer , blocked , interval ) ) ;
914897 }
915898 }
916899
@@ -938,36 +921,33 @@ describe("run-queue gate-blocked variants benchmark", () => {
938921 "commands per acknowledgement, by waiters on the released gate" ,
939922 async ( { redisContainer } ) => {
940923 const results : Array < Record < string , number | string | boolean > > = [ ] ;
941- for ( const vtime of SCRIPTS ) {
942- for ( const waiters of [ 0 , 1 , 10 ] ) {
943- const queue = createQueue ( redisContainer , vtime ) ;
944- try {
945- await queue . redis . flushdb ( ) ;
946- await queue . updateQueueConcurrencyLimits ( env , QUEUE , 50 ) ;
947- await queue . updateQueueConcurrencyLimits ( env , GATE , 1 ) ;
948- const shard = keys . masterQueueShardForEnvironment ( env . id , SHARD_COUNT ) ;
949- const t0 = Date . now ( ) - 600_000 ;
950- await enqueue ( queue , "holder" , "tA-hold" , "tA" , t0 ) ;
951- await queue . testDequeueFromMasterQueue ( shard , env . id , MAX_COUNT ) ;
952- for ( let i = 0 ; i < waiters ; i ++ ) {
953- await enqueue ( queue , `a-blocked-${ i } ` , `tA-s${ i } ` , "tA" , t0 + 1 + i ) ;
954- }
955- await queue . testDequeueFromMasterQueue ( shard , env . id , MAX_COUNT ) ;
956- await queue . redis . call ( "CONFIG" , "RESETSTAT" ) ;
957- await queue . acknowledgeMessage ( env . organization . id , "holder" , {
958- skipDequeueProcessing : true ,
959- } ) ;
960- const side = await redisSide ( queue ) ;
961- results . push ( {
962- script : vtime ? "vtime" : "age-order" ,
963- skipAhead : SKIP_AHEAD ,
964- waiters,
965- ackCommands : side . commands ,
966- ackScriptUs : side . scriptUsec ,
967- } ) ;
968- } finally {
969- await queue . quit ( ) ;
924+ for ( const waiters of [ 0 , 1 , 10 ] ) {
925+ const queue = createQueue ( redisContainer ) ;
926+ try {
927+ await queue . redis . flushdb ( ) ;
928+ await queue . updateQueueConcurrencyLimits ( env , QUEUE , 50 ) ;
929+ await queue . updateQueueConcurrencyLimits ( env , GATE , 1 ) ;
930+ const shard = keys . masterQueueShardForEnvironment ( env . id , SHARD_COUNT ) ;
931+ const t0 = Date . now ( ) - 600_000 ;
932+ await enqueue ( queue , "holder" , "tA-hold" , "tA" , t0 ) ;
933+ await queue . testDequeueFromMasterQueue ( shard , env . id , MAX_COUNT ) ;
934+ for ( let i = 0 ; i < waiters ; i ++ ) {
935+ await enqueue ( queue , `a-blocked-${ i } ` , `tA-s${ i } ` , "tA" , t0 + 1 + i ) ;
970936 }
937+ await queue . testDequeueFromMasterQueue ( shard , env . id , MAX_COUNT ) ;
938+ await queue . redis . call ( "CONFIG" , "RESETSTAT" ) ;
939+ await queue . acknowledgeMessage ( env . organization . id , "holder" , {
940+ skipDequeueProcessing : true ,
941+ } ) ;
942+ const side = await redisSide ( queue ) ;
943+ results . push ( {
944+ skipAhead : SKIP_AHEAD ,
945+ waiters,
946+ ackCommands : side . commands ,
947+ ackScriptUs : side . scriptUsec ,
948+ } ) ;
949+ } finally {
950+ await queue . quit ( ) ;
971951 }
972952 }
973953 await mkdir ( OUT_DIR , { recursive : true } ) ;
@@ -981,10 +961,8 @@ describe("run-queue gate-blocked variants benchmark", () => {
981961 redisTest ( "fresh arrivals behind a keyed gate at its cap" , async ( { redisContainer } ) => {
982962 const results : Array < Record < string , number | string | boolean > > = [ ] ;
983963 for ( const live of process . env . BENCH_ARRIVAL_PACING === "live" ? [ true ] : [ false , true ] ) {
984- for ( const vtime of SCRIPTS ) {
985- for ( const blocked of ARRIVAL_BLOCKED ) {
986- results . push ( await runArrivalScenario ( redisContainer , vtime , blocked , live ) ) ;
987- }
964+ for ( const blocked of ARRIVAL_BLOCKED ) {
965+ results . push ( await runArrivalScenario ( redisContainer , blocked , live ) ) ;
988966 }
989967 }
990968
@@ -1008,10 +986,8 @@ describe("run-queue gate-blocked variants benchmark", () => {
1008986 } ) ;
1009987 redisTest ( "a capped tenant whose runs complete" , async ( { redisContainer } ) => {
1010988 const results : Array < Record < string , number | string | boolean > > = [ ] ;
1011- for ( const vtime of SCRIPTS ) {
1012- for ( const blocked of WAKE_BLOCKED ) {
1013- results . push ( await runWakeScenario ( redisContainer , vtime , blocked ) ) ;
1014- }
989+ for ( const blocked of WAKE_BLOCKED ) {
990+ results . push ( await runWakeScenario ( redisContainer , blocked ) ) ;
1015991 }
1016992 await mkdir ( OUT_DIR , { recursive : true } ) ;
1017993 const outPath = join ( OUT_DIR , "run-queue-gate-wake.json" ) ;
@@ -1038,9 +1014,7 @@ describe("run-queue gate-blocked variants benchmark", () => {
10381014
10391015 redisTest ( "a freed slot reaching a waiter on another queue" , async ( { redisContainer } ) => {
10401016 const results : Array < Record < string , number | string | boolean > > = [ ] ;
1041- for ( const vtime of SCRIPTS ) {
1042- results . push ( await runCrossQueueScenario ( redisContainer , vtime ) ) ;
1043- }
1017+ results . push ( await runCrossQueueScenario ( redisContainer ) ) ;
10441018 await mkdir ( OUT_DIR , { recursive : true } ) ;
10451019 const outPath = join ( OUT_DIR , "run-queue-gate-cross-queue.json" ) ;
10461020 await writeFile ( outPath , JSON . stringify ( { results } , null , 2 ) ) ;
@@ -1049,9 +1023,7 @@ describe("run-queue gate-blocked variants benchmark", () => {
10491023 } ) ;
10501024 redisTest ( "a settled backlog of blocked sub-queues" , async ( { redisContainer } ) => {
10511025 const results : Array < Record < string , number | string | boolean > > = [ ] ;
1052- for ( const vtime of SCRIPTS ) {
1053- results . push ( ...( await runSteadyScenario ( redisContainer , vtime ) ) ) ;
1054- }
1026+ results . push ( ...( await runSteadyScenario ( redisContainer ) ) ) ;
10551027 await mkdir ( OUT_DIR , { recursive : true } ) ;
10561028 const outPath = join ( OUT_DIR , "run-queue-gate-steady.json" ) ;
10571029 await writeFile ( outPath , JSON . stringify ( { results } , null , 2 ) ) ;
@@ -1060,9 +1032,7 @@ describe("run-queue gate-blocked variants benchmark", () => {
10601032 } ) ;
10611033 redisTest ( "many gate pools with capacity freed on another queue" , async ( { redisContainer } ) => {
10621034 const results : Array < Record < string , number | string | boolean > > = [ ] ;
1063- for ( const vtime of SCRIPTS ) {
1064- results . push ( await runManyPoolsScenario ( redisContainer , vtime ) ) ;
1065- }
1035+ results . push ( await runManyPoolsScenario ( redisContainer ) ) ;
10661036 await mkdir ( OUT_DIR , { recursive : true } ) ;
10671037 const outPath = join ( OUT_DIR , "run-queue-gate-pools.json" ) ;
10681038 await writeFile ( outPath , JSON . stringify ( { results } , null , 2 ) ) ;
0 commit comments