-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseqpacket_memory.js
63 lines (55 loc) · 1.28 KB
/
seqpacket_memory.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { SeqpacketServer, SeqpacketSocket } = require('../js/index');
const path = require('path');
const fs = require('fs');
const kSockets = 4;
const kDataSize = 20 * 1024;
const kTimes = 20;
console.log('pid', process.pid);
const kServerPath = path.resolve(
__dirname,
'../__test__/.tmp/seqpacket_memory.sock'
);
try {
fs.unlinkSync(kServerPath);
} catch (err) {
//
}
const server = new SeqpacketServer();
server.listen(kServerPath);
server.on('connection', (socket) => {
socket.on('data', (buf) => {});
socket.on('end', () => {
socket.destroy();
});
});
async function test() {
for (let i = 0; i < kSockets; i += 1) {
const socket = new SeqpacketSocket();
socket.connect(kServerPath, async () => {
const pList = [];
for (let j = 0; j < kTimes; j += 1) {
const buf = Buffer.allocUnsafe(kDataSize);
const p = new Promise((resolve, reject) => {
socket.write(buf, 0, buf.length, () => {
resolve();
});
});
pList.push(p);
}
await Promise.all(pList);
socket.end(() => {
socket.destroy();
});
});
}
}
async function main() {
setInterval(() => {
test();
if (global.gc) {
global.gc();
}
console.log(process.memoryUsage());
}, 500);
}
main();