-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path3-descriptor.js
More file actions
42 lines (34 loc) · 841 Bytes
/
3-descriptor.js
File metadata and controls
42 lines (34 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const fs = require('node:fs');
const memory = [];
const bytesToMb = (bytes) => Math.round(bytes / 1000, 2) / 1000;
let descriptor = 0;
const timer = setInterval(() => {
const handler = (err, fd) => {
descriptor = fd;
};
for (let i = 0; i < 3; i++) {
fs.open('3-descriptor.js', handler);
}
}, 5);
setInterval(() => {
console.clear();
const usage = process.memoryUsage();
const row = {
rss: bytesToMb(usage.rss),
heapTotal: bytesToMb(usage.heapTotal),
heapUsed: bytesToMb(usage.heapUsed),
external: bytesToMb(usage.external),
stack: bytesToMb(usage.rss - usage.heapTotal),
descriptor,
};
memory.push(row);
console.table(memory);
}, 1000);
setTimeout(() => {
clearInterval(timer);
}, 10000);
setTimeout(() => {
console.log(descriptor);
process.exit(0);
}, 15000);