Permalink
Browse files

examples/load_test client: connect queued not parallel

  • Loading branch information...
1 parent 4eb5abb commit 9042c46592d0e145cd25ef209c5817c50565d741 @astro astro committed Mar 30, 2012
Showing with 19 additions and 8 deletions.
  1. +19 −8 examples/load_test/client.js
@@ -8,20 +8,31 @@ function getNow() {
}
function connectThem(n, opts, cb) {
- var funs = [];
+ var queue = async.queue(function(task, cb) {
+ var cl = new xmpp.Client(opts);
+ cl.on('online', function() {
+ cb(null, cl);
+ });
+ cl.on('error', function(e) {
+ cb(e);
+ });
+ }, 100);
+
+ var cls = [];
+ var done = 0;
for(var i = 0; i < n; i++) {
- funs.push(function(cb2) {
- var cl = new xmpp.Client(opts);
- cl.on('online', function() {
- cb2(null, cl);
- });
+ queue.push({}, function(err, cl) {
+ if (cl)
+ cls.push(cl);
+ done++;
+ if (done >= n)
+ cb(null, cls);
});
}
- async.parallel(funs, cb);
}
-const SIZES = [1, 5, 10, 20, 50, 100, 200, 500, 1000, 2000];
+const SIZES = [1, 5, 10, 20, 50, 100, 200, 500, 1000, 1500, 5000];
// TODO: wait for 'close' after end()
async.forEachSeries(SIZES, function(n, cb) {
async.series([function(cb2) {

0 comments on commit 9042c46

Please sign in to comment.