Commit f7775ebb authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Add WebSocket perf tests.

This CL adds a websocket performance test where client receives arrayuffer of 1 mega bytes 100 times.

Test:
$ cd third_party/blink/perf_tests/websocket
$ npm install
$ npm start
$ python ../../../../tools/perf/run_benchmark run blink_perf --browser=canary --test-path=websocket\receive-arraybuffer-1MBx100.html
or open the file directly on browser.

Rough result (avg ms of 6 runs) on Windows10, 28-core CPU of 2.6GHz:
  Chrome Canary(m75): 1709
  Canary w/o extension: 637
  FireFox: 338

Bug: 954000
Change-Id: Ica622aba18d57af2c97f11019588762544008d6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1573436Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653497}
parent b89ac77e
node_modules
\ No newline at end of file
{
"name": "ws-speed-test",
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"async-limiter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
},
"ws": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz",
"integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==",
"requires": {
"async-limiter": "~1.0.0"
}
}
}
}
{
"name": "ws-speed-test",
"version": "0.1.0",
"dependencies": {
"ws": "^5.2.2"
}
}
<!DOCTYPE html>
<html>
<head>
<script src="../resources/runner.js"></script>
</head>
<body>
<script>
// To run this perf test, you need to run the web socket server:
// $ cd third_party/blink/perf_tests/websocket
// $ npm install
// $ npm start
// $ python ../../../../tools/perf/run_benchmark run blink_perf --browser=canary --test-path=websocket\receive-arraybuffer-1MBx100.html
async function runTestCase() {
const ws = new WebSocket("ws://127.0.0.1:8001/");
ws.binaryType = "arraybuffer";
const onOpen = new Promise(resolve => {
ws.onopen = () => {
PerfTestRunner.addRunTestStartMarker();
resolve(PerfTestRunner.now());
};
});
const onClose = new Promise(resolve => {
ws.onclose = () => {
PerfTestRunner.addRunTestEndMarker();
resolve(PerfTestRunner.now());
}
});
const [openTime, closeTime] = await Promise.all([onOpen, onClose]);
PerfTestRunner.measureValueAsync(closeTime - openTime);
}
let isDone = false;
PerfTestRunner.startMeasureValuesAsync({
description: "Measure performance of receiving 1MB array 100 times.",
unit: 'ms',
done: function () {
isDone = true;
},
run: async function() {
while (!isDone) await runTestCase();
},
iterationCount: 6,
});
</script>
</body>
</html>
const ws = require('ws')
const ws_server = new ws.Server({ host: '0.0.0.0', port: 8001 });
const getNow = () => {
const date = new Date();
return date.toLocaleTimeString() + "." + date.getMilliseconds();
};
console.log(getNow() + " WebSocket server started.");
const arrayBuf = 1000*1000; // 1MB
const totalIter = 100;
ws_server.on('connection', function(ws_socket) {
console.log(getNow() + " Connection established.");
const data = new ArrayBuffer(arrayBuf);
for (let i = 0; i < totalIter; i++) {
ws_socket.send(data, {binary: true});
}
ws_socket.close();
console.log(getNow() + " Connection closed.");
});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment