1

I am doing a super basic http request app in node.js.

var http = require('http');

var options = {
  host: 'www.domain-here.com',
  port: 80,
  path: '/index.html'
};

for(var i = 0; i < 500; i++) {
    http.get(options, function(res) {
            console.log("[" + this.count + "] Response: " + res.statusCode);
    }.bind({ count: i })).on('error', function(e) {
            console.log("[" + this.count + "] Error: " + e.message);
    }.bind({ count: i }));
}

I need to get the number of http requests per second though. Any idea how I go about getting requests per second?

2 Answers 2

3
// begin timestamp
var begin = new Date();

for(var i = 0; i < 500; i++) {
    http.get(options, function(res) {
            console.log("[" + this.count + "] Response: " + res.statusCode);
    }.bind({ count: i })).on('error', function(e) {
            console.log("[" + this.count + "] Error: " + e.message);
    }.bind({ count: i }));
}

// end timestamp
var end = new Date();

// Then, you need a simple calculation
var reqPerSec = i / ( end - begin );
Sign up to request clarification or add additional context in comments.

Comments

0

Use the Date object to log the time and analyze the numbers afterwards.

Or You could use a setInterval in combination with a counter variable if you need real time data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.