bench-rest icon indicating copy to clipboard operation
bench-rest copied to clipboard

How to use runOptions

Open sriram289 opened this issue 8 years ago • 2 comments

I have setup a script with runOptions but I am not sure how do I execute the script to use runOptions rather than using bench-rest -n 1000 -c 50 perf_scripts.js ? Am quite new to javascript so apologise if its a very silly question

sriram289 avatar Aug 03 '17 02:08 sriram289

Well if you are running the command from the command line then you can just provide whatever options you want using the -n and -c arguments. You don't need a runOptions in that case.

You would simply define your flow in a js file like this:

var flow = {
    main: [
      { put: 'http://localhost:8000/foo_#{INDEX}', json: 'mydata_#{INDEX}' },
      { get: 'http://localhost:8000/foo_#{INDEX}' }
    ]
  };

  // if the above flow will be used with the command line runner or
  // programmatically from a separate file then export it.
  module.exports = flow;

and run with bench-rest -n 1000 -c 50 perf_scripts.js


If however for some reason you wanted to put those run options into a Node.js script to run, then you would put everything in a script like from the README and run with node perf_script.js

  var benchrest = require('bench-rest');

  // This does a unique PUT and then a GET for each iteration
  var flow = {
    main: [
      { put: 'http://localhost:8000/foo_#{INDEX}', json: 'mydata_#{INDEX}' },
      { get: 'http://localhost:8000/foo_#{INDEX}' }
    ]
  };

  var runOptions = {
    limit: 10,     // concurrent connections
    iterations: 100  // number of iterations to perform
  };
  benchrest(flow, runOptions)
    .on('error', function (err, ctxName) { console.error('Failed in %s with err: ', ctxName, err); })
    .on('end', function (stats, errorCount) {
      console.log('error count: ', errorCount);
      console.log('stats', stats);
    });

jeffbski avatar Aug 04 '17 13:08 jeffbski

thanks for the reply

sriram289 avatar Aug 21 '17 02:08 sriram289