From 754ebead86ad029935ea86fa392e760fed4471a9 Mon Sep 17 00:00:00 2001 From: KeithKelleher Date: Tue, 26 Apr 2022 16:15:52 -0400 Subject: [PATCH] add command to monitor memory --- load_test.js | 66 ++++++++++++++++++++++++---------------------------- package.json | 1 + server.ts | 11 +++++++++ 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/load_test.js b/load_test.js index 0877ad5b6..d7b469a2b 100644 --- a/load_test.js +++ b/load_test.js @@ -1,43 +1,39 @@ const axios = require('axios'); +const fs = require('fs'); +const routes = fs.readFileSync('./routes.txt').toString().split('\n'); +console.log(routes); let count = 0; async function load_test() { - // await axios.get('http://localhost:4000/targets/drd2').then(res => { - // console.log(++count); - // }).catch(err => { - // console.log('error on ' + count); - // // console.log(err); - // }); - // await axios.get('http://localhost:4000/targets').then(res => { - // console.log(++count); - // }).catch(err => { - // console.log('error on ' + count); - // // console.log(err); - // }); - // await axios.get('http://localhost:4000/analyze/targets').then(res => { - // console.log(++count); - // }).catch(err => { - // console.log('error on ' + count); - // // console.log(err); - // }); - await axios.get('http://localhost:4000').then(res => { - console.log(++count); - }).catch(err => { - console.log('error on ' + count); - // console.log(err); - }); + while(true) { + await axios.get('http://localhost:4000/targets').then(res => { + console.log(res); + }); + } + + if (true) { + for (let i = 0; i < routes.length; i++) { + // console.log(routes[i]); + await axios.get('http://localhost:4000' + routes[i]).then(res => { + console.log('done ' + routes[i]); + }).catch(err => { + console.log('error on ' + count); + // console.log(err); + }); + } + } } load_test(); -load_test(); -load_test(); -load_test(); -load_test(); -setInterval(() => { - load_test(); - load_test(); - load_test(); - load_test(); - load_test(); -}, 10000); +// load_test(); +// load_test(); +// load_test(); +// load_test(); +// setInterval(() => { +// load_test(); +// // load_test(); +// // load_test(); +// // load_test(); +// // load_test(); +// }, 10000); diff --git a/package.json b/package.json index 8c21abd8a..cc786a6d7 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "build:ssr": "npm --no-git-tag-version version patch && npm run prerender", "build:ssr:dev": "ng build && ng run pharos:server:development", "serve:ssr": "node dist/server/main.js", + "perfmon": "node dist/server/main.js perf", "rerun:ssr": "npm run build:ssr && say pharos is ready && npm run serve:ssr", "dev:ssr": "ng run pharos:serve-ssr", "prerender": "ng run pharos:prerender" diff --git a/server.ts b/server.ts index 725dad6b7..e9929f5bd 100644 --- a/server.ts +++ b/server.ts @@ -3,6 +3,7 @@ import 'zone.js/node'; import { ngExpressEngine } from '@nguniversal/express-engine'; import * as express from 'express'; import { join } from 'path'; +const {performance} = require('perf_hooks'); import { AppServerModule } from './src/main.server'; import { APP_BASE_HREF } from '@angular/common'; @@ -43,6 +44,16 @@ export function app() { return server; } +const args = process.argv.slice(2); + +if (args && args.length > 0 && args[0] === 'perf') { + console.log('time, heapTotal, heapUsed, external'); + setInterval(() => { + const mem = process.memoryUsage(); + console.log(`${performance.now()}, ${mem.heapTotal / (1024 * 1024)}, ${mem.heapUsed / (1024 * 1024)}, ${mem.external / (1024 * 1024)}`); + }, 5000); +} + function run() { const port = process.env.PORT || 4000;