Permalink
Browse files

First working implementation

  • Loading branch information...
1 parent c5ee343 commit dc22541f89ccc6ab35f103d0fca2611a24d20a6a @rmehner rmehner committed Oct 6, 2011
Showing with 44 additions and 1 deletion.
  1. +2 −0 .gitignore
  2. +26 −0 index.js
  3. +16 −1 package.json
View
2 .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
View
26 index.js
@@ -0,0 +1,26 @@
+var port = 3030;
+var interval = 1000;
+var duration = 10 * 1000;
+var receivedCounter = 0;
+var sockets = [];
+var io = require('socket.io').listen(port);
+
+io.sockets.on('connection', function (socket) {
+ sockets.push(socket);
+ socket.on('chat.send', function(data) {
+ receivedCounter++;
+ });
+});
+
+setInterval(function() {
+ sockets.forEach(function(socket) {
+ socket.emit('chat.msg', {
+ msg: 'JavaScript motherfucker. Do you speak it!'
+ });
+ });
+}, interval);
+
+setInterval(function() {
+ console.log('Received %d requests per second', receivedCounter / (duration * 1000));
+ receivedCounter = 0;
+}, duration);
View
17 package.json
@@ -1 +1,16 @@
-{}
+{
+ "author": "Robin Mehner <robin@coding-robin.de>",
+ "name": "socketio-bench-server",
+ "description": "Small socket.io server bench",
+ "version": "0.0.0",
+ "repository": {
+ "url": ""
+ },
+ "engines": {
+ "node": "~0.4.12"
+ },
+ "dependencies": {
+ "socket.io": "~0.8.4"
+ },
+ "devDependencies": {}
+}

0 comments on commit dc22541

Please sign in to comment.