Created
June 11, 2012 11:51
-
-
Save xinz/2909735 to your computer and use it in GitHub Desktop.
the websocket benchmark client via the WebSocket-Node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intro: | |
About the `WebSocket-Node' part please refer https://github.com/Worlize/WebSocket-Node for details. | |
The above client part wants to roughly test the max concurrency connections of the websocket server, loop send UTF content to server and broadcast its updates to | |
other connected clients. | |
Issue: | |
Since i don't find any up-to-date websocket testing tool like "ab or siege", I am using the "&"(node ./wsclient_test.js &) to mock the concurrence processes, but after i | |
execute the first time test command ("sh ./test.sh"), i will find that there won't be able to setup the expected number of the node processes, | |
the catched error is "Connect Error: Error: connect ETIMEDOUT", meanwhile the client and server's CPU is not 100% consumed, and the memory still have many available, | |
i try to run many times test shell(sh ./test.sh) and there will some new connections are established, but the "ETIMEDOUT" is frequently happened. | |
The testing client and the server are two machines in LAN, (Pentium(R) Dual-Core CPU E5300 @ 2.60GHz, 8G RAM, x86_64 GNU/Linux), the "ulimit" settings as following: | |
core file size (blocks, -c) 0 | |
data seg size (kbytes, -d) unlimited | |
scheduling priority (-e) 0 | |
file size (blocks, -f) unlimited | |
pending signals (-i) 60803 | |
max locked memory (kbytes, -l) 32 | |
max memory size (kbytes, -m) unlimited | |
open files (-n) 65535 | |
pipe size (512 bytes, -p) 8 | |
POSIX message queues (bytes, -q) 819200 | |
real-time priority (-r) 0 | |
stack size (kbytes, -s) 10240 | |
cpu time (seconds, -t) unlimited | |
max user processes (-u) 60803 | |
virtual memory (kbytes, -v) unlimited | |
file locks (-x) unlimited | |
node version:v0.6.19 | |
WebSocket-Node version:1.0.6 | |
I am a newbie about the "ws" benchmark, could you please kindly advice any ideas how can i do the benchmark for the concurrency connections(aviod the "ETIMEDOUT" issue | |
as much as possible)? | |
So far, the server supports 2651 clients(this number maybe can be increased, if i try to renew more executions for the "sh ./test.sh") | |
Server: | |
Cpu(s): 42.4%us, 4.2%sy, 0.0%ni, 49.5%id, 0.0%wa, 0.0%hi, 3.8%si, 0.2%st | |
Client: | |
Cpu(s): 29.3%us, 7.0%sy, 0.0%ni, 63.2%id, 0.0%wa, 0.0%hi, 0.2%si, 0.3%st | |
Thanks in advance! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
x=1 | |
while [ $x -le 30 ] | |
do | |
echo "start $x instance" | |
node ./wsclient_test.js & | |
x=$(( $x + 1 )) | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
function start_one_client() { | |
var WebSocketClient = require('websocket').client; | |
var client = new WebSocketClient(); | |
var _id = new Date().getTime(); | |
client.on('connectFailed', function(error) { | |
console.log('Connect Error: ' + error.toString()); | |
}); | |
client.on('connect', function(connection) { | |
console.log('WebSocket client connected'); | |
connection.on('error', function(error) { | |
console.log("Connection Error: " + error.toString()); | |
}); | |
connection.on('close', function() { | |
console.log('online protocol Connection Closed'); | |
}); | |
connection.on('message', function(message) { | |
if (message.type === 'utf8') { | |
console.log("Received: '" + message.utf8Data + "'"); | |
} | |
}); | |
function sendNumber() { | |
if (connection.connected) { | |
var a = parseInt(Math.random()*100+1); | |
var b = parseInt(Math.random()*100+1); | |
msg = {sns_id:_id, data:{x:a, y:b}} | |
connection.sendUTF(JSON.stringify(msg)); | |
setTimeout(sendNumber, 10000); | |
} | |
} | |
sendNumber(); | |
}); | |
client.connect('ws://host:8084/online'); | |
} | |
for(var i=0;i<100;i++){ | |
console.log("start " + i + " websocket client"); | |
start_one_client(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment