feat: multiprocessing and some diagnostics
This commit is contained in:
parent
86e437a23a
commit
c75319d166
4 changed files with 40 additions and 9 deletions
|
|
@ -2,6 +2,11 @@ const https = require('https')
|
|||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const uuid = require('uuid')
|
||||
const _ = require('lodash/fp')
|
||||
const { PerformanceObserver, performance } = require('perf_hooks')
|
||||
|
||||
const utils = require('./utils')
|
||||
const variables = require('./utils/variables')
|
||||
|
||||
function getCert (machineIndex) {
|
||||
try {
|
||||
|
|
@ -23,8 +28,11 @@ function connectionInfo (machineIndex) {
|
|||
}
|
||||
|
||||
let counter = 0
|
||||
const requestTimes = []
|
||||
let latestResponseTime = 0
|
||||
|
||||
function request (machineIndex, pid) {
|
||||
performance.mark('A')
|
||||
https.get({
|
||||
hostname: 'localhost',
|
||||
port: 3000,
|
||||
|
|
@ -39,6 +47,9 @@ function request (machineIndex, pid) {
|
|||
}
|
||||
}, res => {
|
||||
res.on('data', (d) => {
|
||||
performance.mark('B')
|
||||
performance.measure('A to B', 'A', 'B')
|
||||
console.log(`Machine ${machineIndex} || Avg request response time: ${_.mean(requestTimes).toFixed(3)} || Latest response time: ${latestResponseTime.toFixed(3)}`)
|
||||
process.send({ message: Buffer.from(d).toString() })
|
||||
})
|
||||
})
|
||||
|
|
@ -46,9 +57,17 @@ function request (machineIndex, pid) {
|
|||
counter++
|
||||
}
|
||||
|
||||
process.on('message', (msg) => {
|
||||
const obs = new PerformanceObserver((items) => {
|
||||
latestResponseTime = items.getEntries()[0].duration
|
||||
requestTimes.push(latestResponseTime)
|
||||
performance.clearMarks()
|
||||
})
|
||||
obs.observe({ entryTypes: ['measure'] })
|
||||
|
||||
process.on('message', async (msg) => {
|
||||
console.log('Message from parent:', msg)
|
||||
|
||||
if (msg.hasVariance) await new Promise(resolve => setTimeout(resolve, utils.randomIntFromInterval(1, variables.POLLING_INTERVAL)))
|
||||
const pid = uuid.v4()
|
||||
request(msg.machineIndex, pid)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue