2021-12-01 16:26:13 +00:00
|
|
|
'use strict';
|
|
|
|
|
2021-12-01 22:30:10 +00:00
|
|
|
const util = require('util');
|
2021-12-01 16:26:13 +00:00
|
|
|
const fs = require('fs').promises;
|
|
|
|
const Promise = require('bluebird');
|
|
|
|
const { JSDOM } = require('jsdom');
|
|
|
|
|
2021-12-01 22:30:10 +00:00
|
|
|
const waitImmediate = util.promisify(setImmediate);
|
|
|
|
|
2021-12-01 16:26:13 +00:00
|
|
|
async function init() {
|
|
|
|
let peak = 0;
|
|
|
|
const files = await fs.readdir('./html');
|
|
|
|
|
|
|
|
await Promise.map(Array.from({ length: 10 }).map(() => files).flat(), async (filename) => {
|
|
|
|
const html = await fs.readFile(`./html/${filename}`, 'utf8');
|
|
|
|
const dom = new JSDOM(html);
|
|
|
|
|
|
|
|
dom.window.close();
|
|
|
|
|
|
|
|
const usage = process.memoryUsage.rss() / 1000000;
|
|
|
|
peak = Math.max(usage, peak);
|
|
|
|
|
|
|
|
console.log(`Memory usage: ${usage.toFixed(2)} MB, peak ${peak.toFixed(2)} MB`);
|
|
|
|
|
2021-12-01 22:30:10 +00:00
|
|
|
await waitImmediate;
|
2021-12-01 16:26:13 +00:00
|
|
|
}, {
|
2021-12-01 22:30:10 +00:00
|
|
|
concurrency: 100,
|
2021-12-01 16:26:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await Promise.delay(2000);
|
|
|
|
|
|
|
|
console.log(`Final memory usage: ${(process.memoryUsage.rss() / 1000000).toFixed(2)} MB, max ${peak.toFixed(2)} MB`);
|
|
|
|
}
|
|
|
|
|
|
|
|
init();
|