-
-
Save adrianlee/5253538 to your computer and use it in GitHub Desktop.
This file contains 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
var | |
PARALLEL_CONNECTS = 10, | |
http = require('http'), | |
sys = require('sys'), | |
connectionCount = 0, | |
messageCount = 0; | |
lastMessages = 0; | |
function addClient() { | |
var client = http.createClient(8000); | |
client.setTimeout(0); | |
client.addListener('connect', function() { | |
connectionCount++; | |
addClient(); | |
}); | |
client.addListener('close', function() { | |
connectionCount--; | |
}); | |
var request = client.request("GET", "/", {"host": "localhost"}); | |
request.finish(function (res) { | |
res.addListener('body', function() { | |
messageCount++; | |
lastMessages++; | |
}); | |
}); | |
}; | |
for (var i = 0; i < PARALLEL_CONNECTS; i++) { | |
addClient(); | |
} | |
var lastCheck = +(new Date); | |
setInterval(function() { | |
var | |
duration = ((+(new Date) - lastCheck) / 1000), | |
messagesPerSec = (lastMessages / duration).toFixed(0); | |
sys.puts( | |
(new Date).toISOString()+": "+ | |
connectionCount+' connections, '+ | |
messageCount+' messages received ('+ | |
messagesPerSec+' messages / sec)' | |
); | |
lastMessages = 0; | |
lastCheck = +(new Date); | |
}, 1000); |
This file contains 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
# http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-2/ | |
SERVERPID=`pgrep -f 'node server.js'`; while [ 1 ] ; do NUMCON=`netstat -n | awk '/ESTABLISHED/ && $4=="127.0.0.1:8000"' | wc -l`; MEM=`ps -o rss= -p $SERVERPID`; echo -e "`date`\t`date +%s`\t$MEM\t $NUMCON"; sleep 1; done |
This file contains 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
var http = require('http'); | |
var server = http.createServer(function(req, res) { | |
req.connection.setTimeout(0); | |
res.sendHeader(200, {'Content-Type': 'text/plain'}); | |
setInterval(function() { | |
res.sendBody("Hello\n"); | |
res.flush(); | |
}, 10000); | |
}); | |
server.listen(8000); |
This file contains 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
# See http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-3/ | |
net.core.rmem_max = 33554432 | |
net.core.wmem_max = 33554432 | |
net.ipv4.tcp_rmem = 4096 16384 33554432 | |
net.ipv4.tcp_wmem = 4096 16384 33554432 | |
net.ipv4.tcp_mem = 786432 1048576 26777216 | |
net.ipv4.tcp_max_tw_buckets = 360000 | |
net.core.netdev_max_backlog = 2500 | |
vm.min_free_kbytes = 65536 | |
vm.swappiness = 0 | |
net.ipv4.ip_local_port_range = 1024 65535 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment