Browse files

websocket connection stress test

  • Loading branch information...
1 parent 2c069e3 commit 2889984bc24d2d385dc54acbcf4620454d21f604 @tjanczuk tjanczuk committed Oct 23, 2012
View
5 src/iisnode/iisnode.vcxproj
@@ -350,7 +350,12 @@ copy /y $(ProjectDir)\..\config\* $(ProjectDir)\..\..\build\$(Configuration)\$(P
<None Include="..\..\test\performance\www\default\web.config" />
<None Include="..\..\test\stress\130_websocket_chat\index.html" />
<None Include="..\..\test\stress\130_websocket_chat\server.js" />
+ <None Include="..\..\test\stress\130_websocket_chat\setup.bat" />
<None Include="..\..\test\stress\130_websocket_chat\web.config" />
+ <None Include="..\..\test\stress\131_websoket_connections\index.html" />
+ <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="..\config\iisnode_dev_x64.xml">
<SubType>Designer</SubType>
</None>
View
18 src/iisnode/iisnode.vcxproj.filters
@@ -162,6 +162,9 @@
<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>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
@@ -723,6 +726,21 @@
<None Include="..\..\test\stress\130_websocket_chat\index.html">
<Filter>Tests\stress\132_websoket_chat</Filter>
</None>
+ <None Include="..\..\test\stress\131_websoket_connections\index.html">
+ <Filter>Tests\stress\131_websocket_connections</Filter>
+ </None>
+ <None Include="..\..\test\stress\131_websoket_connections\server.js">
+ <Filter>Tests\stress\131_websocket_connections</Filter>
+ </None>
+ <None Include="..\..\test\stress\131_websoket_connections\setup.bat">
+ <Filter>Tests\stress\131_websocket_connections</Filter>
+ </None>
+ <None Include="..\..\test\stress\131_websoket_connections\web.config">
+ <Filter>Tests\stress\131_websocket_connections</Filter>
+ </None>
+ <None Include="..\..\test\stress\130_websocket_chat\setup.bat">
+ <Filter>Tests\stress\132_websoket_chat</Filter>
+ </None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="iisnode.rc" />
View
144 test/stress/131_websoket_connections/index.html
@@ -0,0 +1,144 @@
+<html>
+<head>
+ <title>130_websocket_connections</title>
+ <script src="http://code.jquery.com/jquery-latest.js"></script>
+</head>
+<body>
+ <h1>130_websocket_connections</h1>
+ <table>
+ <tr>
+ <td>Running time:</td>
+ <td id="time">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Messages sent:</td>
+ <td id="sent">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Messages received:</td>
+ <td id="received">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Websockets opened [total]:</td>
+ <td id="wscount">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Websockets opened [current]:</td>
+ <td id="wscurrent">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Websocket errors:</td>
+ <td id="errors">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Distinct node.exe PIDs:</td>
+ <td id="pids">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Last RSS of node.exe:</td>
+ <td id="rss">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Last heap total of node.exe:</td>
+ <td id="heaptotal">&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Last heap used of node.exe:</td>
+ <td id="heapused">&nbsp;</td>
+ </tr>
+ </table>
+ <script>
+ var start = new Date().getTime();
+ var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
+ var address = protocol + window.location.host + window.location.pathname + '/server.js';
+ var errors = 0;
+ var wscount = 0;
+ var sent = 0;
+ var received = 0;
+ var lastPID = -1;
+ var pids = 0;
+ var sendFrequency = 200;
+ var sendCount = 5;
+ var maxErrors = 100;
+ var concurrentWebSockets = 50;
+ var warmupPeriod = 10000; // ms
+ var stop;
+ var wscurrent = 0;
+
+ function openSocket() {
+ var socket = new WebSocket(address);
+ wscount++;
+ $('#wscount').html(wscount);
+ wscurrent++;
+ $('#wscurrent').html(wscurrent);
+
+ socket.onmessage = function (msg) {
+ var json = JSON.parse(msg.data);
+ received++;
+ $('#received').html(received);
+ if (json.pid != lastPID) {
+ pids++;
+ lastPID = json.pid;
+ $('#pids').html(pids);
+ }
+ $('#rss').html(json.memory.rss);
+ $('#heaptotal').html(json.memory.heapTotal);
+ $('#heapused').html(json.memory.heapUsed);
+ };
+
+ socket.onerror = function (e) {
+ errors++;
+ $('#errors').html(errors);
+ if (errors > maxErrors) {
+ stop = true;
+ clearInterval(elapsedTime);
+ }
+ };
+
+ socket.onclose = function () {
+ socket = null;
+ wscurrent--;
+ $('#wscurrent').html(wscurrent);
+ if (!stop) {
+ openSocket();
+ }
+ };
+
+ var count = 0;
+ var sendTimer = setInterval(function () {
+ count++;
+ if (socket && count <= sendCount && !stop) {
+ socket.send('Check out the Websockets through iisnode!');
+ sent++;
+ $('#sent').html(sent);
+ }
+ else {
+ clearInterval(sendTimer);
+ if (socket) {
+ socket.close();
+ }
+ }
+ }, sendFrequency);
+ }
+
+ var elapsedTime = setInterval(function () {
+ var diff = new Date().getTime() - start;
+ var days = Math.floor(diff / (24 * 3600 * 1000));
+ diff %= (24 * 3600 * 1000);
+ var hours = Math.floor(diff / (3600 * 1000));
+ diff %= (3600 * 1000);
+ var minutes = Math.floor(diff / (60 * 1000));
+ diff %= (60 * 1000);
+ var seconds = Math.floor(diff / 1000);
+ $('#time').html(days + 'd ' + hours + 'h ' + minutes + 'm ' + seconds + 's');
+ }, 1000);
+
+ for (var i = 0; i < concurrentWebSockets; i++) {
+ setTimeout(function () {
+ openSocket();
+ }, Math.floor(warmupPeriod * Math.random()));
+ }
+
+ </script>
+</body>
+</html>
View
30 test/stress/131_websoket_connections/server.js
@@ -0,0 +1,30 @@
+
+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(JSON.stringify({
+ message: event.data,
+ pid: process.pid,
+ memory: process.memoryUsage()
+ }));
+ }
+ catch (e) {
+ }
+ };
+
+ ws.onclose = function (event) {
+ ws = null;
+ };
+});
+
+server.listen(process.env.PORT || 8888);
View
1 test/stress/131_websoket_connections/setup.bat
@@ -0,0 +1 @@
+%systemroot%\system32\inetsrv\appcmd.exe add app /site.name:"Default Web Site" /path:/131_websocket_connections /physicalPath:%~dp0 /applicationPool:DefaultAppPool
View
8 test/stress/131_websoket_connections/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 2889984

Please sign in to comment.