Skip to content

Instantly share code, notes, and snippets.

@ingeniarius
Created September 25, 2011 07:35
Show Gist options
  • Save ingeniarius/1240345 to your computer and use it in GitHub Desktop.
Save ingeniarius/1240345 to your computer and use it in GitHub Desktop.
Socket.IO benchmark
/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:610
transport.payload(this.closed[data.id]);
^
TypeError: Object #<WebSocket> has no method 'payload'
at Manager.handleClient (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:610:19)
at Manager.handleUpgrade (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:564:8)
at HTTPServer.<anonymous> (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:100:10)
at HTTPServer.emit (events.js:81:20)
at Socket.<anonymous> (http.js:1035:14)
at Socket._onReadable (net.js:683:27)
at IOWatcher.onReadable [as callback] (net.js:177:10)
<!DOCTYPE html>
<html>
<head>
<title>socket.io item</title>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" charset="utf-8">
var socket = io.connect('http://localhost:5000/');
setInterval(function() { socket.send('Echo ' + Math.random()) }, 1000);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>socket.io benchmark</title>
</head>
<body>
<iframe id="iframe" src="iframe.html" width="10" height="10"></iframe>
<script>
var iframe = document.getElementById('iframe');
var i = 0;
function connect() {
if (i < 100) {
i++;
document.body.appendChild(document.createTextNode(i + ':'));
document.body.appendChild(iframe.cloneNode());
setTimeout(connect, 10);
}
}
connect();
</script>
</body>
</html>
/**
* Module dependencies.
*/
const express = require('express');
const sio = require('socket.io');
const sys = require('sys');
const url = require('url');
/**
* App server
*/
var app = express.createServer();
app.configure(function () {
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/public');
});
app.get('/', function (req, res) {
res.render('index', { layout: false });
});
app.listen(5000, function () {
var addr = app.address();
sys.log('app listening on http://' + addr.address + ':' + addr.port);
});
function memoryUsage() {
console.log('! Memory usage:', process.memoryUsage().rss / 1024 / 1024, 'Mb');
}
/**
* Socket.IO server (single process only)
*/
var io = sio.listen(app);
io.configure(function (){
io.set('log level', 3);
io.set('transports', ['websocket', 'xhr-polling']);
});
io.sockets.on('connection', function (client, fn) {
client.broadcast.send('Hello from ' + client.id);
client.on('message', function(message) {
client.broadcast.send(message);
});
memoryUsage();
});
setInterval(memoryUsage, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment