Last active
December 17, 2015 19:48
-
-
Save marcosnils/5662575 to your computer and use it in GitHub Desktop.
Request performance test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.