Skip to content

Instantly share code, notes, and snippets.

@marcosnils
Last active December 17, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcosnils/5662575 to your computer and use it in GitHub Desktop.
Save marcosnils/5662575 to your computer and use it in GitHub Desktop.
Request performance test.
var request = require("request"),
http = require("http");
var time;
var plainBody = {"resource":"/test/1111111111111","user_id":15667236,"topic":"test","attempts":1,"sent":"2013-05-27T19:15:17.043Z","received":"2013-05-27T19:15:15.000Z"}
var body = JSON.stringify(plainBody);
var nodeReq = function() {
time = Date.now();
var req = http.request({
hostname: "httpbin.org",
path: "/post",
headers: {"content-length":body.length},
method: "POST"}, function(res) {
console.log(res.statusCode);
res.on("data", function(){});
console.log("Node req took: ",Date.now() - time);
})
req.write(body);
req.end();
}
var req = function() {
time = Date.now();
request({
url: "http://httpbin.org/post",
method: "POST",
body: body,
}, function(error, response, body) {
console.log(response.statusCode);
console.log("Request took: ",Date.now() - time);
});
}
setInterval(nodeReq, 1000);
//setInterval(req, 1000);
@marcosnils
Copy link
Author

200
Request took: 557
200
Request took: 506
200
Request took: 524
200
Request took: 519
200
Request took: 504


200
Node req took: 349
200
Node req took: 357
200
Node req took: 346
200
Node req took: 345

@mikeal
Copy link

mikeal commented May 28, 2013

Yeah, there's going to be a few ms delay in request because it hangs on nextTick() to finish the underlying http request object. This is so that you can get some of the fancier streaming capabilities as well as not having to call .end() for GET and HEAD requests.

100ms seems rather long though, I wonder if there is something else we're doing that is adding some delay.

There's a lot of refactoring coming soon, especially around the agent and how we do writes, I'll add some benchmarks around that time to make sure we're getting faster instead of slower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment