Skip to content

Commit

Permalink
Merge pull request #9606 from gsnedders/update_pywebsockets
Browse files Browse the repository at this point in the history
Update pywebsockets
  • Loading branch information
gsnedders authored Feb 21, 2018
2 parents d6dc97a + 31b28c7 commit 3881189
Show file tree
Hide file tree
Showing 98 changed files with 1,054 additions and 820 deletions.
2 changes: 1 addition & 1 deletion tools/localpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sys.path.insert(0, os.path.join(here, "six"))
sys.path.insert(0, os.path.join(here, "html5lib"))
sys.path.insert(0, os.path.join(here, "wptserve"))
sys.path.insert(0, os.path.join(here, "pywebsocket", "src"))
sys.path.insert(0, os.path.join(here, "pywebsocket"))
sys.path.insert(0, os.path.join(here, "third_party", "attrs", "src"))
sys.path.insert(0, os.path.join(here, "third_party", "funcsigs"))
sys.path.insert(0, os.path.join(here, "third_party", "pluggy"))
Expand Down
11 changes: 11 additions & 0 deletions tools/pywebsocket/CONTRIBUTING
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
For instructions for contributing code, please read:
https://github.com/google/pywebsocket/wiki/CodeReviewInstruction

You must complete the Individual Contributor License Agreement.
https://cla.developers.google.com/about/google-individual
You can do this online, and it only takes a minute.

If you are contributing on behalf of a corporation, you must fill out the
Corporate Contributor License Agreement
https://cla.developers.google.com/about/google-corporate
and send it to us as described on that page.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions tools/pywebsocket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# pywebsocket #

The pywebsocket project aims to provide a [WebSocket](https://tools.ietf.org/html/rfc6455) standalone server and a WebSocket extension for [Apache HTTP Server](https://httpd.apache.org/), mod\_pywebsocket.

pywebsocket is intended for **testing** or **experimental** purposes.

Please see [Wiki](../../wiki) for more details.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -52,65 +52,35 @@
// If the size of each message is small, send/receive multiple messages
// until the sum of sizes reaches this threshold.
minTotal: getIntFromInput('mintotal'),
multipliers: getIntArrayFromInput('multipliers'),
verifyData: getBoolFromCheckBox('verifydata')
multipliers: getFloatArrayFromInput('multipliers'),
verifyData: getBoolFromCheckBox('verifydata'),
addToLog: addToLog,
addToSummary: addToSummary,
measureValue: measureValue,
notifyAbort: notifyAbort
};
}

var worker = new Worker('benchmark.js');
worker.onmessage = onMessage;

function onSendBenchmark() {
var config = getConfig();

if (getBoolFromCheckBox('worker')) {
worker.postMessage({type: 'sendBenchmark', config: config});
} else {
config.addToLog = addToLog;
config.addToSummary = addToSummary;
config.measureValue = measureValue;
sendBenchmark(config);
}
doAction(config, getBoolFromCheckBox('worker'), 'sendBenchmark');
}

function onReceiveBenchmark() {
var config = getConfig();

if (getBoolFromCheckBox('worker')) {
worker.postMessage({type: 'receiveBenchmark', config: config});
} else {
config.addToLog = addToLog;
config.addToSummary = addToSummary;
config.measureValue = measureValue;
receiveBenchmark(config);
}
doAction(config, getBoolFromCheckBox('worker'), 'receiveBenchmark');
}

function onBatchBenchmark() {
var config = getConfig();

if (getBoolFromCheckBox('worker')) {
worker.postMessage({type: 'batchBenchmark', config: config});
} else {
config.addToLog = addToLog;
config.addToSummary = addToSummary;
config.measureValue = measureValue;
batchBenchmark(config);
}
doAction(config, getBoolFromCheckBox('worker'), 'batchBenchmark');
}

function onStop() {
var config = getConfig();

if (getBoolFromCheckBox('worker')) {
worker.postMessage({type: 'stop', config: config});
} else {
config.addToLog = addToLog;
config.addToSummary = addToSummary;
config.measureValue = measureValue;
stop(config);
}
doAction(config, getBoolFromCheckBox('worker'), 'stop');
}

function init() {
addressBox = document.getElementById('address');
logBox = document.getElementById('log');
Expand All @@ -128,6 +98,8 @@
if (!('WebSocket' in window)) {
addToLog('WebSocket is not available');
}

initWorker('WebSocket', '');
}
</script>
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function destroyAllSockets() {
sockets = [];
}

function sendBenchmarkStep(size, config) {
function sendBenchmarkStep(size, config, isWarmUp) {
timerID = null;

var totalSize = 0;
Expand All @@ -41,6 +41,7 @@ function sendBenchmarkStep(size, config) {
var onMessageHandler = function(event) {
if (!verifyAcknowledgement(config, event.data, size)) {
destroyAllSockets();
config.notifyAbort();
return;
}

Expand All @@ -50,7 +51,8 @@ function sendBenchmarkStep(size, config) {
return;
}

calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize);
calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize,
isWarmUp);

runNextTask(config);
};
Expand Down Expand Up @@ -89,7 +91,7 @@ function sendBenchmarkStep(size, config) {
}
}

function receiveBenchmarkStep(size, config) {
function receiveBenchmarkStep(size, config, isWarmUp) {
timerID = null;

var totalSize = 0;
Expand All @@ -101,12 +103,14 @@ function receiveBenchmarkStep(size, config) {
config.addToLog('Expected ' + size + 'B but received ' +
bytesReceived + 'B');
destroyAllSockets();
config.notifyAbort();
return;
}

if (config.verifyData && !verifyArrayBuffer(event.data, 0x61)) {
config.addToLog('Response verification failed');
destroyAllSockets();
config.notifyAbort();
return;
}

Expand All @@ -116,7 +120,8 @@ function receiveBenchmarkStep(size, config) {
return;
}

calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize);
calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize,
isWarmUp);

runNextTask(config);
};
Expand Down Expand Up @@ -153,12 +158,11 @@ function createSocket(config) {
};
socket.onclose = function(event) {
config.addToLog('Closed');
config.notifyAbort();
};
return socket;
}

var tasks = [];

function startBenchmark(config) {
clearTimeout(timerID);
destroyAllSockets();
Expand All @@ -180,24 +184,6 @@ function startBenchmark(config) {
}
}

function runNextTask(config) {
var task = tasks.shift();
if (task == undefined) {
config.addToLog('Finished');
destroyAllSockets();
return;
}
timerID = setTimeout(task, 0);
}

function buildLegendString(config) {
var legend = ''
if (config.printSize)
legend = 'Message size in KiB, Time/message in ms, ';
legend += 'Speed in kB/s';
return legend;
}

function getConfigString(config) {
return '(WebSocket' +
', ' + (typeof importScripts !== "undefined" ? 'Worker' : 'Main') +
Expand All @@ -209,69 +195,6 @@ function getConfigString(config) {
')';
}

function addTasks(config, stepFunc) {
for (var i = 0;
i < config.numWarmUpIterations + config.numIterations; ++i) {
// Ignore the first |config.numWarmUpIterations| iterations.
if (i == config.numWarmUpIterations)
addResultClearingTask(config);

var multiplierIndex = 0;
for (var size = config.startSize;
size <= config.stopThreshold;
++multiplierIndex) {
var task = stepFunc.bind(
null,
size,
config);
tasks.push(task);
size *= config.multipliers[
multiplierIndex % config.multipliers.length];
}
}
}

function addResultReportingTask(config, title) {
tasks.push(function(){
timerID = null;
config.addToSummary(title);
reportAverageData(config);
clearAverageData();
runNextTask(config);
});
}

function addResultClearingTask(config) {
tasks.push(function(){
timerID = null;
clearAverageData();
runNextTask(config);
});
}

function sendBenchmark(config) {
config.addToLog('Send benchmark');
config.addToLog(buildLegendString(config));

tasks = [];
clearAverageData();
addTasks(config, sendBenchmarkStep);
addResultReportingTask(config, 'Send Benchmark ' + getConfigString(config));
startBenchmark(config);
}

function receiveBenchmark(config) {
config.addToLog('Receive benchmark');
config.addToLog(buildLegendString(config));

tasks = [];
clearAverageData();
addTasks(config, receiveBenchmarkStep);
addResultReportingTask(config,
'Receive Benchmark ' + getConfigString(config));
startBenchmark(config);
}

function batchBenchmark(config) {
config.addToLog('Batch benchmark');
config.addToLog(buildLegendString(config));
Expand All @@ -286,24 +209,6 @@ function batchBenchmark(config) {
startBenchmark(config);
}

function stop(config) {
clearTimeout(timerID);
timerID = null;
config.addToLog('Stopped');
function cleanup() {
destroyAllSockets();
}

onmessage = function (message) {
var config = message.data.config;
config.addToLog = workerAddToLog;
config.addToSummary = workerAddToSummary;
config.measureValue = workerMeasureValue;
if (message.data.type === 'sendBenchmark')
sendBenchmark(config);
else if (message.data.type === 'receiveBenchmark')
receiveBenchmark(config);
else if (message.data.type === 'batchBenchmark')
batchBenchmark(config);
else if (message.data.type === 'stop')
stop(config);
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3881189

Please sign in to comment.