@@ -14,10 +14,10 @@ import {
1414 IComputeEnvironment ,
1515 ISchedulingPolicy ,
1616 JobQueue ,
17- QueueMetrics ,
17+ QueueHistory ,
1818} from './scheduling' ;
1919
20- const NUMBER_OF_JOBS : number = 20000 ;
20+ const DEFAULT_NUMBER_OF_JOBS : number = 10000 ;
2121
2222export interface StochasticModel {
2323 readonly interArrivalTimeDistribution : IDistribution ;
@@ -120,8 +120,8 @@ export class JobGenerator {
120120
121121 private generateRandomJobs ( ) : Job [ ] {
122122 let time = 0 ;
123- const jobs : Job [ ] = new Array < Job > ( NUMBER_OF_JOBS ) ;
124- for ( let i = 0 ; i < NUMBER_OF_JOBS ; i ++ ) {
123+ const jobs : Job [ ] = new Array < Job > ( DEFAULT_NUMBER_OF_JOBS ) ;
124+ for ( let i = 0 ; i < DEFAULT_NUMBER_OF_JOBS ; i ++ ) {
125125 const c = Math . floor ( Math . random ( ) * this . models . length ) ;
126126 const jobDefinition : IJobDefinition = this . models [ c ] . jobDefinition ;
127127 const rng : RandomNumberGenerator = this . rngs [ c ] ;
@@ -154,8 +154,10 @@ export class JobGenerator {
154154 * Generates a random number from a geometric distribution
155155 */
156156function geometric ( successProbability : number ) : number {
157+ if ( successProbability === 1 ) return 1 ;
157158 return Math . ceil ( Math . log ( Math . random ( ) ) / Math . log ( 1 - successProbability ) ) ;
158159}
160+
159161function validateConfigs ( configs : StochasticModel [ ] ) {
160162 // TODO test this
161163 if ( configs . some ( c => c . weightFactorProbabilities != null
@@ -200,7 +202,7 @@ interface SimulationResult {
200202 readonly timesByJobDefinition : Map < string , Histogram > ;
201203 readonly meanTimeByShareIdentifier : Map < string , number > ;
202204 readonly meanTimeByJobDefinition : Map < string , number > ;
203- readonly queueSize : QueueMetrics [ ] ;
205+ readonly queueHistories : QueueHistory [ ] ;
204206}
205207
206208export interface IBatchSimulator < M > {
@@ -291,7 +293,10 @@ export class Simulator {
291293 eventLoop . start ( ) ;
292294
293295 const metrics : ExecutionMetrics [ ] = backlogs . flatMap ( b => b . queue . executionMetrics ) ;
294- const queueSizeMetric : QueueMetrics [ ] = backlogs . flatMap ( b => b . queue . queueMetrics ) ;
296+ const queueHistories : QueueHistory [ ] = backlogs . map ( b => ( {
297+ id : b . queue . queueId ,
298+ metrics : b . queue . queueMetrics ,
299+ } ) ) ;
295300 const map : Map < Job , number > = new Map ( metrics . map ( m => [ m . job , m . time ] ) ) ;
296301
297302 const timesByShareIdentifier = this . aggregateByShareIdentifier ( map ) ;
@@ -313,7 +318,7 @@ export class Simulator {
313318 timesByJobDefinition,
314319 meanTimeByShareIdentifier,
315320 meanTimeByJobDefinition,
316- queueSize : queueSizeMetric ,
321+ queueHistories ,
317322 } ) ;
318323 }
319324
@@ -364,6 +369,7 @@ class ConstructConverter {
364369 schedulingPolicy : this . convertSchedulingPolicy ( queue . schedulingPolicy ) ,
365370 computeEnvironments : queue . computeEnvironments . map ( e => this . convertComputeEnvironment ( e . computeEnvironment ) ) ,
366371 eventLoop : this . eventLoop ,
372+ queueId : queue . node . path ,
367373 } ) ;
368374 }
369375
@@ -433,6 +439,14 @@ export class SimulationReport {
433439 return result ;
434440 } ;
435441
442+ const generateQueueDivs = ( ) => {
443+ const result : string [ ] = [ ] ;
444+ this . simulationResult . queueHistories . forEach ( history => {
445+ result . push ( `<div id="q-${ history . id } "></div>` ) ;
446+ } ) ;
447+ return result ;
448+ } ;
449+
436450 const generateCalls = ( ) => {
437451 const calls : string [ ] = [ ] ;
438452 const header : [ any , any ] [ ] = [ [ 'Time' , '' ] ] ;
@@ -442,20 +456,20 @@ export class SimulationReport {
442456 this . simulationResult . timesByJobDefinition . forEach ( ( histogram , jobDefinition ) => {
443457 calls . push ( `drawChart('jd-${ jobDefinition } ', '${ jobDefinition } (μ = ${ this . simulationResult . meanTimeByJobDefinition . get ( jobDefinition ) } )', ${ JSON . stringify ( header . concat ( histogram . entries ( ) ) ) } );` ) ;
444458 } ) ;
459+ calls . push ( ...generateQueueHistories ( ) ) ;
445460 return calls . join ( '\n' ) ;
446461 } ;
447462
448- const generateQueueSize = ( ) => {
449- const header : [ any , any ] [ ] = [ [ 'Time' , 'Number of jobs' ] ] ;
450- const data : [ number , number ] [ ] = this . simulationResult . queueSize
451- . map ( m => [ m . time , m . size ] ) ;
452- const sortedData : [ number , number ] [ ] = data
453- . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] )
454- . filter ( ( _ , i ) => i % 10 === 0 ) ;
455-
456- return `drawChart('queue-size', 'Queue size', ${ JSON . stringify ( header . concat ( sortedData ) ) } , 'Line');` ;
463+ const generateQueueHistories = ( ) => {
464+ return this . simulationResult . queueHistories . map ( history => {
465+ const header : [ any , any ] [ ] = [ [ 'Time' , 'Number of jobs' ] ] ;
466+ const data : [ number , number ] [ ] = history . metrics . map ( p => ( [ p . time , p . size ] ) ) ;
467+ const sortedData : [ number , number ] [ ] = data
468+ . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] )
469+ . filter ( ( _ , i ) => i % 10 === 0 ) ;
470+ return `drawChart('q- ${ history . id } ', ' ${ history . id } ', ${ JSON . stringify ( header . concat ( sortedData ) ) } , 'Line');` ;
471+ } ) ;
457472 } ;
458-
459473 return `
460474<html>
461475<head>
@@ -482,7 +496,7 @@ export class SimulationReport {
482496
483497 function drawCharts() {
484498 ${ generateCalls ( ) }
485- ${ generateQueueSize ( ) }
499+
486500 }
487501 </script>
488502</head>
@@ -499,9 +513,9 @@ ${generateShareIdDivs().join('')}
499513${ generateJobDefinitionDivs ( ) . join ( '' ) }
500514</div>
501515
502- <h2>Queue size </h2>
516+ <h2>Queue histories </h2>
503517<div bp="full-width">
504- <div id="queue-size" />
518+ ${ generateQueueDivs ( ) . join ( '' ) }
505519</div>
506520
507521</body>
0 commit comments