Tuesday, March 25, 2014

Load Testing Websockets


Determine the load the system can handle in websocket connections.


The difficulty is that websockets require a "handshake" to transform a http request to a tcp connection. I initial looked at Gatling ( http://gatling-tool.org/) with the websockets addon( https://github.com/gilt/gatling-websocket ). But I did not want learn scala or performing scripting. I wanted something that displayed output like apache bench. My research led me to Thor (https://www.npmjs.org/package/thor)


Centos 5.8 x86_64
npm (node package module )

Install nodes.js

We have a user thor which we are going to run thor
cd /home/thor
wget http://nodejs.org/dist/v0.10.26/node-v0.10.26-linux-x64.tar.gz
tar -xvf node-v0.10.26-linux-x64.tar.gz

vi hello_nodes.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js\n');
}).listen(8124, "server");
console.log('Server running at http://server:8124/');

./node-v0.10.26-linux-x64/bin/node hello_node.js
Server running at http://server:8124/

In a browser : http://server:8124/

Install npm

My first attempt to install on Centos 5.8 was to find the rpms. npm and nodes.js was suppose to be in epel repo.

wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm -Uvh epel-release-5-4.noarch.rpm
yum search --enablerepo=epel-testing --enablerepo=epel npm
No Matches found

yum provides --enablerepo=epel-testing --enablerepo=epel npm */npm
No Matches found

I decided to build from source

export PATH=$PATH:/home/thor/node-v0.10.26-linux-x64/bin
yum install git -y
git clone https://github.com/npm/npm.git
cd npm
make install
cd ..

which npm

Install Thor

npm install thor

You can setup an apache tomcat websocket server Here.

 ./npm/node_modules/thor/bin/thor --amount 100 ws://websocket:8080/examples/websocket/chat
 ./npm/node_modules/thor/bin/thor --amount 1000 ws://websocket:8080/examples/websocket/chat
 ./npm/node_modules/thor/bin/thor --amount 100 --concurrent 5 ws://websocket:8080/examples/websocket/chat


 ./npm/node_modules/thor/bin/thor --amount 100 ws://websocket:9090/examples/websocket/chat
 ./npm/node_modules/thor/bin/thor --amount 1000 ws://websocket:9090/examples/websocket/chat
 ./npm/node_modules/thor/bin/thor --amount 100 --concurrent 5 ws://websocket:9090/examples/websocket/chat


Thor:                                                  version: 1.0.0

God of Thunder, son of Odin and smasher of WebSockets!

Thou shall:
- Spawn 1 workers.
- Create 2 concurrent/parallel connections.
- Smash 100 connections with the mighty Mjölnir.

The answers you seek shall be yours, once I claim what is mine.

Connecting to ws://websocket:8080/examples/websocket/chat

  Opened 100 connections

Online               439 milliseconds
Time taken           441 milliseconds
Connected            100
Disconnected         0
Failed               0
Total transferred    132.62kB
Total received       71.85kB

Durations (ms):

                     min     mean     stddev  median max
Handshaking          1       5             3       4 20
Latency              0       0             1       0 3

Percentile (ms):

                      50%     66%     75%     80%     90%     95%     98%     98%    100%
Handshaking          4       5       5       6       7       11      17      20      20
Latency              0       0       1       1       1       1       1       2       3

References: http://howtonode.org/how-to-install-nodejs

No comments:

Post a Comment