Skip to content

Instantly share code, notes, and snippets.

@nicokaiser
nicokaiser / client.js
Created April 11, 2012 21:05
node.js 0.6.x garbage collector fail
var WebSocket = require('ws')
// open 200 connections that close after 5 seconds
for (var i = 0; i < 200; i++) { openWs() }
function openWs() {
var ws = new WebSocket('ws://localhost:8080')
ws.on('open', function() {
ws.send('hello')
setTimeout(function() { ws.close(); }, 5000)
@nicokaiser
nicokaiser / client.js
Created March 21, 2012 21:19
ws memory leak demo
/**
* The client opens 10,000 connections to the server and sends one 10k message.
* Every minutes, 2,000 new connections are openend and 2,000 random connections
* are closed (equally distributed interval).
*/
var util = require('util')
, WebSocket = require('ws');
// Config
@nicokaiser
nicokaiser / echo-server.js
Created March 13, 2012 21:09
WebSocket.IO Leak Test
var http = require('http')
, net = require('net')
, util = require('util')
, wsio = require('websocket.io');
var server = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('ok');
});
@nicokaiser
nicokaiser / client.js
Created November 23, 2011 22:29
websocket.io Issue #6
var util = require('util')
, WebSocket = require('websocket-server').WebSocket;
var CONCURRENCY = 200;
var SERVER = 'ws://localhost:3000/';
for (var i = 0; i < CONCURRENCY; i++) {
createConnection();
}
var mongodb = require('mongodb');
// This example selects all documents of a collection and checks if they should be displayed.
// 15 documents should be displayed, but I have to select all from the DB because maybe
// myCheckFunction returns true only for the last 15 elements selected (if any).
// So at some point (if I have seen enough documents) the DB can stop sending me documents,
// i.e. not fetch another batch of 30 documents in this case.
var db = new mongodb.Db('mydb', new mongodb.Server('localhost', 27017, {}));
@nicokaiser
nicokaiser / websocket-protocol-fallback.js
Created September 15, 2011 12:54
WebSocket library fallback for old protocol clients
#!/usr/bin/env node
// Example of how to fallback to alternative websocket library for old protocol clients
// see https://gist.github.com/1148686
var http = require('http'),
WebSocketRequest = require('websocket').request,
ws = require('websocket-server');