diff --git a/bin/load_gen b/bin/load_gen index 5b771a95474e5c06477f1a1096360a3458ce2c5b..99a4e08e93d9d4031a1c73ed61bd696c4e58e28c 100755 --- a/bin/load_gen +++ b/bin/load_gen @@ -42,12 +42,15 @@ const winston = require('winston'); - // option processing with optimist var argv = require('optimist') .usage('Apply load to a BrowserID server.\nUsage: $0', [ "foo" ]) +.alias('a', 'activities') +.describe('a', 'only run a subset of activities, specified as a CSV list') .alias('h', 'help') .describe('h', 'display this usage message') +.alias('l', 'list') +.describe('l', 'list available activities and exit') .alias('m', 'max') .describe('m', 'maximum active users to simulate (0 == infinite)') .default('m', 10000) @@ -131,6 +134,31 @@ var activity = { } }; +if (args.l) { + console.log("available activities:", Object.keys(activity).join(", ")); + process.exit(0); +} + +var activitiesToRun = Object.keys(activity); + +// handle modification of activities to run (-o or -a) +if (args.a) { + if (typeof args.a !== 'string') { + process.stdout.write("invalid argument: " + args.a.toString() + "\n\n"); + argv.showHelp(); + process.exit(1); + } + activitiesToRun = args.a.split(','); + activitiesToRun.forEach(function(act) { + if (!activity.hasOwnProperty(act)) { + process.stdout.write("invalid activity: " + act + "\n\n"); + process.exit(1); + } + }); +} else if (args.o) { + activitiesToRun.splice(activitiesToRun.indexOf('include_only'), 1); +} + // outstanding incomplete activites var outstanding = { }; @@ -196,9 +224,8 @@ function poll() { break; } } - // start the activity! (except if it's an include_only and we're - // in 'omit static' mode - if (!args.o || act !== 'include_only') { + // start the activity! (if it is enabled) + if (activitiesToRun.indexOf(act) !== -1) { outstanding[act]++; activity[act].startFunc(configuration, function(err) { if (err) winston.error(err); diff --git a/lib/configuration.js b/lib/configuration.js index b6523801135ed7dc8d4538efe43ed4cc5d83fc18..41293f4cd8548fea39009223e7cd4d10884933e0 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -106,11 +106,6 @@ g_configs.local = { min_time_between_emails_ms: g_configs.production.min_time_between_emails_ms }; -if (undefined !== process.env['NODE_EXTRA_CONFIG']) { - var fs = require('fs'); - eval(fs.readFileSync(process.env['NODE_EXTRA_CONFIG']) + ''); -} - // test environments are variations on local g_configs.test_json = JSON.parse(JSON.stringify(g_configs.local)); g_configs.test_json.database = { @@ -124,6 +119,11 @@ g_configs.test_mysql.database = { create_schema: true }; +if (undefined !== process.env['NODE_EXTRA_CONFIG']) { + var fs = require('fs'); + eval(fs.readFileSync(process.env['NODE_EXTRA_CONFIG']) + ''); +} + // default deployment is local if (undefined === process.env['NODE_ENV']) { process.env['NODE_ENV'] = 'local';