File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -91,11 +91,27 @@ class Benchmark {
9191 }
9292
9393 async runSubTests ( ) {
94+ const workerGroups = this . splitWorkerRunGroups ( ) ;
95+ if ( workerGroups . length != MAX_CONCURRENT_RUNNING )
96+ throw new Error ( `Invalid workerGroups.length, got ${ workerGroups . length } expected ${ MAX_CONCURRENT_RUNNING } ` ) ;
97+ // Run each worker group in parallel.
98+ await Promise . all ( workerGroups . map ( group => this . runGroupWorkloads ( group ) ) ) ;
99+ }
100+
101+ splitWorkerRunGroups ( ) {
94102 const workers = this . workers . slice ( ) ;
103+ const groups = new Array ( MAX_CONCURRENT_RUNNING ) . fill ( null ) . map ( _ => [ ] ) ;
104+ let groupIndex = 0 ;
95105 while ( workers . length > 0 ) {
96- const workerGroup = workers . splice ( workers . length - MAX_CONCURRENT_RUNNING , MAX_CONCURRENT_RUNNING ) ;
97- await Promise . all ( workerGroup . map ( worker => worker . runWorkload ( ) ) ) ;
106+ groups [ groupIndex % groups . length ] . push ( workers . pop ( ) ) ;
107+ groupIndex ++ ;
98108 }
109+ return groups ;
110+ }
111+
112+ async runGroupWorkloads ( workers ) {
113+ for ( const worker of workers )
114+ await worker . runWorkload ( ) ;
99115 }
100116}
101117
You can’t perform that action at this time.
0 commit comments