Skip to content

Commit 00d1356

Browse files
author
ionut.stan
committed
Benchmark.
1 parent 879db5d commit 00d1356

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

tests/AllTests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class AllTests
248248
});
249249

250250
this._httpServerSiteA = null;
251+
global.gc();
251252
}
252253

253254

@@ -1186,6 +1187,7 @@ class AllTests
11861187

11871188
if(this._bBenchmarkMode)
11881189
{
1190+
console.log("heapTotal: " + Math.round(process.memoryUsage().heapTotal / 1024 / 1024, 2) + " MB");
11891191
this.disableConsole();
11901192
}
11911193
}

tests/benchmark.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,38 @@ process.on(
1717
const bBenchmarkMode = true;
1818

1919

20-
console.log("===== http (500 calls in parallel)");
21-
let allTests = new AllTests(bBenchmarkMode, /*bWebSocketMode*/ false, undefined, undefined, undefined, /*bDisableVeryLargePacket*/ true);
22-
await allTests.runTests();
23-
24-
console.log("===== ws (20,000 calls in parallel, over as many reused connections as possible)");
25-
allTests = new AllTests(bBenchmarkMode, /*bWebSocketMode*/ true, require("ws"), require("ws").Server, undefined, /*bDisableVeryLargePacket*/ true);
26-
await allTests.runTests();
27-
28-
// Super bug: somehow V8 is deoptimized here (win 10, 64 bit).
29-
// Running ws first will show ws is faster. Running uws first, will show uws is faster.
30-
31-
console.log("===== uws (20,000 calls in parallel, over as many reused connections as possible)");
32-
allTests = new AllTests(bBenchmarkMode, /*bWebSocketMode*/ true, require("uws"), require("uws").Server, JSONRPC.WebSocketAdapters.uws.WebSocketWrapper, /*bDisableVeryLargePacket*/ true);
33-
allTests.websocketServerPort = allTests.httpServerPort + 1;
34-
await allTests.runTests();
35-
36-
// uws is consistently slower than ws when benchmarking with a few open connections (2) with the same number of calls.
37-
// Most of the randomness was disabled when tested.
38-
// Tested on nodejs 7.8.0, Windows 10, 64 bit.
39-
40-
console.log("[" + process.pid + "] Finished all tests!!!");
20+
let nPasses = 5;
21+
let allTests;
22+
while(nPasses--)
23+
{
24+
//console.log("===== http (500 calls in parallel)");
25+
//allTests = new AllTests(bBenchmarkMode, /*bWebSocketMode*/ false, undefined, undefined, undefined, /*bDisableVeryLargePacket*/ true);
26+
//await allTests.runTests();
27+
//global.gc();
28+
//console.log("heapTotal after gc(): " + Math.round(process.memoryUsage().heapTotal / 1024 / 1024, 2) + " MB");
29+
//console.log("");
30+
31+
// uws is consistently slower than ws when benchmarking with a few open connections (2) with the same number of calls.
32+
// Most of the randomness was disabled when tested.
33+
// Tested on nodejs 7.8.0, Windows 10, 64 bit.
34+
console.log("===== uws (20,000 calls in parallel, over as many reused connections as possible)");
35+
allTests = new AllTests(bBenchmarkMode, /*bWebSocketMode*/ true, require("uws"), require("uws").Server, JSONRPC.WebSocketAdapters.uws.WebSocketWrapper, /*bDisableVeryLargePacket*/ true);
36+
allTests.websocketServerPort = allTests.httpServerPort + 1;
37+
await allTests.runTests();
38+
global.gc();
39+
console.log("heapTotal after gc(): " + Math.round(process.memoryUsage().heapTotal / 1024 / 1024, 2) + " MB");
40+
console.log("");
41+
42+
43+
console.log("===== ws (20,000 calls in parallel, over as many reused connections as possible)");
44+
allTests = new AllTests(bBenchmarkMode, /*bWebSocketMode*/ true, require("ws"), require("ws").Server, undefined, /*bDisableVeryLargePacket*/ true);
45+
await allTests.runTests();
46+
global.gc();
47+
console.log("heapTotal after gc(): " + Math.round(process.memoryUsage().heapTotal / 1024 / 1024, 2) + " MB");
48+
console.log("");
49+
}
50+
51+
console.log("[" + process.pid + "] Finished benchmarking.");
4152

4253
process.exit(0);
4354
}

0 commit comments

Comments
 (0)