@@ -3,6 +3,9 @@ import { CdkToolkit } from './toolkit';
33import * as app from './src/app' ;
44import microstats from 'microstats' ;
55import { debugModeEnabled } from '@aws-cdk/core/lib/debug' ;
6+ import * as v8 from 'v8' ;
7+
8+ const PAGE_SIZE = parseInt ( process . env . DEPLOY_STACK_PAGE_SIZE ) || 850 ;
69
710process . on ( 'unhandledRejection' , ( reason , _ ) => {
811 console . error ( reason ) ;
@@ -17,16 +20,45 @@ microstats.on('disk', function (value) {
1720microstats . on ( 'cpu' , function ( value ) {
1821 console . log ( 'CPU:' , value ) ;
1922} ) ;
20- let microstatsOptions = { frequency : '5s' } ;
23+ let microstatsOptions = {
24+ frequency : 'onalert' ,
25+ memoryalert : { used : '>80%' } ,
26+ cpualert : { load : '>90%' } ,
27+ diskalert : { used : '>70%' } ,
28+ } ;
2129/**
2230 * Entrypoint for bootstrapping, deploying and synthesizing CDK apps.
2331 */
2432
33+ const convertToMegabytes = ( num : number ) => {
34+ return `${ ( num / 1024 / 1024 ) . toFixed ( 2 ) } MB` ;
35+ } ;
36+
37+ const getHeapStatistics = ( ) => {
38+ const heapstats = v8 . getHeapStatistics ( ) ;
39+
40+ return {
41+ totalHeapSize : convertToMegabytes ( heapstats . total_heap_size ) ,
42+ totalHeapSizeExecutable : convertToMegabytes ( heapstats . total_heap_size_executable ) ,
43+ totalPhysicalSize : convertToMegabytes ( heapstats . total_physical_size ) ,
44+ totalAvailableSize : convertToMegabytes ( heapstats . total_available_size ) ,
45+ usedHeapSize : convertToMegabytes ( heapstats . used_heap_size ) ,
46+ heapSizeLimit : convertToMegabytes ( heapstats . heap_size_limit ) ,
47+ usedHeapSizePercentage : ( ( heapstats . used_heap_size / heapstats . heap_size_limit ) * 100 ) . toFixed ( 2 ) ,
48+ mallocedMemory : convertToMegabytes ( heapstats . malloced_memory ) ,
49+ peakMallocedMemory : convertToMegabytes ( heapstats . peak_malloced_memory ) ,
50+ doesZapGarbage : heapstats . does_zap_garbage ,
51+ nativeContexts : heapstats . number_of_native_contexts ,
52+ detachedContexts : heapstats . number_of_detached_contexts ,
53+ } ;
54+ } ;
55+
2556async function main ( ) {
2657 if ( debugModeEnabled ( ) ) {
2758 microstats . start ( microstatsOptions , err => {
2859 console . log ( err ) ;
2960 } ) ;
61+ console . log ( getHeapStatistics ( ) ) ;
3062 }
3163 const usage = `Usage: cdk.ts <command> [<command>] --phase PHASE [--region REGION] [--account-key ACCOUNT_KEY] [--parallel]` ;
3264 const args = mri ( process . argv . slice ( 2 ) , {
@@ -54,26 +86,29 @@ async function main() {
5486 phaseId : `${ phase } ` ,
5587 region : args . region ,
5688 accountKey : args [ 'account-key' ] ,
57- // Make sure templates and assets do not build in to the same directory
5889 useTempOutputDir : true ,
5990 } ) ;
6091 console . log ( `Total stacks = ${ apps . length } ` ) ;
61- const appDeploymentPaging = [ ] ;
62-
63- const toolkit = await CdkToolkit . create ( apps ) ;
64-
65- if ( commands . includes ( 'bootstrap' ) ) {
66- await toolkit . bootstrap ( ) ;
67- }
68- if ( commands . includes ( 'synth' ) ) {
69- await toolkit . synth ( ) ;
92+ let appsPage = [ ] ;
93+ for ( let i = 0 ; i < apps . length ; i ++ ) {
94+ appsPage . push ( apps [ i ] ) ;
95+ console . log ( `deploying stack ${ i + 1 } of ${ apps . length } ` ) ;
96+ if ( appsPage . length > PAGE_SIZE - 1 || i === apps . length - 1 ) {
97+ const toolkit = await CdkToolkit . create ( appsPage ) ;
98+ if ( commands . includes ( 'bootstrap' ) ) {
99+ await toolkit . bootstrap ( ) ;
100+ }
101+ if ( commands . includes ( 'synth' ) ) {
102+ await toolkit . synth ( ) ;
103+ }
104+ if ( commands . includes ( 'deploy' ) ) {
105+ await toolkit . deployAllStacks ( {
106+ parallel,
107+ } ) ;
108+ }
109+ appsPage = [ ] ;
110+ }
70111 }
71- if ( commands . includes ( 'deploy' ) ) {
72- await toolkit . deployAllStacks ( {
73- parallel,
74- } ) ;
75- }
76-
77112 if ( debugModeEnabled ( ) ) {
78113 microstats . stop ( ) ;
79114 }
0 commit comments