Skip to content

Commit

Permalink
websocket latency test
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanczuk committed Oct 23, 2012
1 parent 6569296 commit a9e145a
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/iisnode/iisnode.vcxproj
Expand Up @@ -356,6 +356,10 @@ copy /y $(ProjectDir)\..\config\* $(ProjectDir)\..\..\build\$(Configuration)\$(P
<None Include="..\..\test\stress\131_websoket_connections\server.js" />
<None Include="..\..\test\stress\131_websoket_connections\setup.bat" />
<None Include="..\..\test\stress\131_websoket_connections\web.config" />
<None Include="..\..\test\stress\132_websocket_latency\index.html" />
<None Include="..\..\test\stress\132_websocket_latency\server.js" />
<None Include="..\..\test\stress\132_websocket_latency\setup.bat" />
<None Include="..\..\test\stress\132_websocket_latency\web.config" />
<None Include="..\config\iisnode_dev_x64.xml">
<SubType>Designer</SubType>
</None>
Expand Down
29 changes: 22 additions & 7 deletions src/iisnode/iisnode.vcxproj.filters
Expand Up @@ -159,12 +159,15 @@
<Filter Include="Tests\stress">
<UniqueIdentifier>{e5dade76-fb92-4baa-a16b-41d7df056829}</UniqueIdentifier>
</Filter>
<Filter Include="Tests\stress\132_websoket_chat">
<UniqueIdentifier>{2081befc-0e1b-498c-b3ca-056e0c37305b}</UniqueIdentifier>
</Filter>
<Filter Include="Tests\stress\131_websocket_connections">
<UniqueIdentifier>{8b577c52-0888-4778-8c01-308bf573cb77}</UniqueIdentifier>
</Filter>
<Filter Include="Tests\stress\130_websocket_chat">
<UniqueIdentifier>{2081befc-0e1b-498c-b3ca-056e0c37305b}</UniqueIdentifier>
</Filter>
<Filter Include="Tests\stress\132_websocket_latency">
<UniqueIdentifier>{44ee30b6-3875-4e2d-99f0-f9e5cf6b38ac}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
Expand Down Expand Up @@ -718,13 +721,13 @@
<Filter>Tests\functional\tests</Filter>
</None>
<None Include="..\..\test\stress\130_websocket_chat\server.js">
<Filter>Tests\stress\132_websoket_chat</Filter>
<Filter>Tests\stress\130_websocket_chat</Filter>
</None>
<None Include="..\..\test\stress\130_websocket_chat\web.config">
<Filter>Tests\stress\132_websoket_chat</Filter>
<Filter>Tests\stress\130_websocket_chat</Filter>
</None>
<None Include="..\..\test\stress\130_websocket_chat\index.html">
<Filter>Tests\stress\132_websoket_chat</Filter>
<Filter>Tests\stress\130_websocket_chat</Filter>
</None>
<None Include="..\..\test\stress\131_websoket_connections\index.html">
<Filter>Tests\stress\131_websocket_connections</Filter>
Expand All @@ -739,7 +742,19 @@
<Filter>Tests\stress\131_websocket_connections</Filter>
</None>
<None Include="..\..\test\stress\130_websocket_chat\setup.bat">
<Filter>Tests\stress\132_websoket_chat</Filter>
<Filter>Tests\stress\130_websocket_chat</Filter>
</None>
<None Include="..\..\test\stress\132_websocket_latency\index.html">
<Filter>Tests\stress\132_websocket_latency</Filter>
</None>
<None Include="..\..\test\stress\132_websocket_latency\server.js">
<Filter>Tests\stress\132_websocket_latency</Filter>
</None>
<None Include="..\..\test\stress\132_websocket_latency\setup.bat">
<Filter>Tests\stress\132_websocket_latency</Filter>
</None>
<None Include="..\..\test\stress\132_websocket_latency\web.config">
<Filter>Tests\stress\132_websocket_latency</Filter>
</None>
</ItemGroup>
<ItemGroup>
Expand Down
116 changes: 116 additions & 0 deletions test/stress/132_websocket_latency/index.html
@@ -0,0 +1,116 @@
<html>
<head>
<title>132_websocket_latency</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<h1>132_websocket_latency</h1>
<p>The iisnode is expected at ws://localhost/132_websocket_latency/server.js. The node.exe is expected at ws://localhost:8888.</p>
<table>
<tr>
<th>Measurement</th>
<th>node.exe</th>
<th>iisnode</th>
</tr>
<tr>
<th>Open latency [ms]</th>
<td id="node-open">...</td>
<td id="iisnode-open">...</td>
</tr>
<tr>
<th>Echo latency [ms]</th>
<td id="node-echo">...</td>
<td id="iisnode-echo">...</td>
</tr>
</table>
<p>Progress: <span id="progress">0%</span></p>
<script>
var start = new Date().getTime();
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
var scenarioAddress = {
iisnode: protocol + window.location.host + window.location.pathname + '/server.js',
node: protocol + 'localhost:8888'
};
var measurements = 30;
var progress = 0;

function measureOne(address, callback) {
var start = new Date().getTime();
var open, receive, error;
var socket = new WebSocket(address);

socket.onopen = function () {
open = new Date().getTime();
socket.send('Hello');
};

socket.onmessage = function () {
receive = new Date().getTime();
socket.close();
};

socket.onerror = function (e) {
error = e;
}

socket.onclose = function () {
callback(error, open ? open - start : undefined, receive ? receive - start: undefined);
};
}

function measureScenario(scenario, callback) {
// warmup
measureOne(scenarioAddress[scenario], function (error) {
if (error) {
return callback(error);
}

// actual test

var count = 0;
var openSum = 0;
var echoSum = 0;

function runOnce() {
measureOne(scenarioAddress[scenario], function (error, open, echo) {
if (error) {
return callback(error);
}

setProgress(++progress);

openSum += open;
echoSum += echo;
count++;
if (count < measurements) {
runOnce();
}
else {
callback(null, openSum / count, echoSum / count);
}
});
}

runOnce();
});
}

function setProgress(p) {
progress = p;
$('#progress').html((100 * p / (measurements * 2)).toFixed(0) + '%');
}

measureScenario('node', function (error, open, echo) {
setProgress(measurements);
$('#node-open').html(error ? error.toString() : open.toFixed(2));
$('#node-echo').html(error ? error.toString() : echo.toFixed(2));
measureScenario('iisnode', function (error, open, echo) {
setProgress(measurements * 2);
$('#iisnode-open').html(error ? error.toString() : open.toFixed(2));
$('#iisnode-echo').html(error ? error.toString() : echo.toFixed(2));
});
});

</script>
</body>
</html>
26 changes: 26 additions & 0 deletions test/stress/132_websocket_latency/server.js
@@ -0,0 +1,26 @@

var WebSocket = require('faye-websocket')
, http = require('http');

var server = http.createServer(function (req, res) {
res.writeHead(400);
res.end();
});

server.addListener('upgrade', function (request, socket, head) {
var ws = new WebSocket(request, socket, head);

ws.onmessage = function (event) {
try {
ws.send(event.data);
}
catch (e) {
}
};

ws.onclose = function (event) {
ws = null;
};
});

server.listen(process.env.PORT || 8888);
1 change: 1 addition & 0 deletions test/stress/132_websocket_latency/setup.bat
@@ -0,0 +1 @@
%systemroot%\system32\inetsrv\appcmd.exe add app /site.name:"Default Web Site" /path:/132_websocket_latency /physicalPath:%~dp0 /applicationPool:DefaultAppPool
8 changes: 8 additions & 0 deletions test/stress/132_websocket_latency/web.config
@@ -0,0 +1,8 @@
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<webSocket enabled="false" />
</system.webServer>
</configuration>

0 comments on commit a9e145a

Please sign in to comment.