Created
October 4, 2019 07:02
-
-
Save raghavgarg1257/03774772492cd05de93fa1105ca5f4dc to your computer and use it in GitHub Desktop.
Box8 Web SSR | memory profiling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const child_process = require('child_process'); | |
const axios = require('axios'); | |
const redis = require('redis'); | |
const client = redis.createClient({ host: '127.0.0.1', port: 6379 }); | |
const stats = { | |
category: [], | |
menu: [], | |
cart: [], | |
}; | |
const child = child_process.fork('./dist/server.js'); | |
console.log('[initialized child process]'); | |
child.on("message", (data) => { | |
if (data.tag === 'initial_value') { | |
Object.keys(stats).forEach(page => stats[page].push(data)); | |
} | |
else { | |
stats[data.tag].push(data); | |
} | |
}); | |
function sleep(time) { | |
return new Promise((resolve, reject) => setTimeout(resolve, time)); | |
} | |
function flushdb() { | |
return new Promise((resolve, reject) => client.flushdb(resolve)); | |
} | |
async function init() { | |
await sleep(2000); | |
child.send('initial_value'); | |
for (let page in stats) { | |
for (let i = 0; i < 5; i++) { | |
await sleep(2000); | |
await flushdb(); | |
await axios.get(`http://localhost:4000/${page}`); | |
child.send(`${page}`); | |
} | |
} | |
await sleep(2000); | |
console.log(require('util').inspect(stats, { depth: null })); | |
child.send('kill_processs'); | |
} | |
init() | |
.then(() => { | |
process.exit(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment