Skip to content

Commit

Permalink
add command to monitor memory
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithKelleher committed Apr 26, 2022
1 parent 96fa6a0 commit 754ebea
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
66 changes: 31 additions & 35 deletions load_test.js
Original file line number Diff line number Diff line change
@@ -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);

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 754ebea

Please sign in to comment.