Created
December 8, 2014 11:29
-
-
Save FREEZX/77012bd8024fdb74f7e7 to your computer and use it in GitHub Desktop.
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
| var async = require('async'); | |
| var benchtest = require('./' + process.argv[2]); | |
| benchtest.prepareClient(parseInt(process.argv[4]), process.argv[3]); | |
| console.log(JSON.stringify({message: 'start'})); | |
| var sockets = parseInt(process.argv[5]); | |
| var messages = parseInt(process.argv[6]); | |
| var q = async.queue(function(task, callback){ | |
| benchtest.test(messages, callback); | |
| }, 50); | |
| for(var i=0; i<sockets; ++i){ | |
| q.push(); | |
| } | |
| q.drain = function() { | |
| console.log(JSON.stringify({message: 'end'})); | |
| process.exit(); | |
| } |
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
| var http = require('http'), | |
| Primus = require('primus'); | |
| var server, primus, Socket, PORT; | |
| exports.prepareServer = function(port, transformer){ | |
| PORT = port; | |
| server = http.createServer(); | |
| primus = new Primus(server, { transformer: transformer }); | |
| primus.on('connection', function connection(spark) { | |
| spark.on('data', function echo(data) { | |
| spark.write(data); | |
| }); | |
| }); | |
| server.listen(PORT); | |
| } | |
| exports.prepareClient = function(port, transformer){ | |
| PORT = port; | |
| Socket = Primus.createSocket({ transformer: transformer }); | |
| } | |
| exports.test = function(messages, done){ | |
| var socket; | |
| var responses = 0; | |
| var url = 'http://localhost:'+PORT; | |
| (function connect() { | |
| socket = new Socket(url); | |
| socket.on('open', function open() { | |
| for (i = 0; i < messages - responses; i++) socket.write('data'); | |
| }); | |
| socket.on('data', function message() { | |
| if (++responses === messages) socket.end(); | |
| }); | |
| socket.on('end', function close() { | |
| if (responses === messages) return done(); | |
| connect(); | |
| }); | |
| })(); | |
| } |
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
| var async = require('async'); | |
| var benchtest = require('./' + process.argv[2]); | |
| var PORT = 3000; | |
| benchtest.prepareServer(PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment