问题
I don't know much about how the https module in node.js works so if any of you can answer this question then that would be great.
I have noticed in a small app I made that it takes about ~150ms for a HTTPS.get(...) function to execute from scratch before any actual request is sent out. This is what im talking about:
var http = require('http');
var https = require('https');
console.time("Begin");
function request() {
console.timeEnd("Begin");
var myvar = https.get("https://www.fiadkbjadfklblnfthiswebsidedoesnotexist.com", function(res) {
});
console.timeEnd("Begin");
}
request();
When I use 'https.get', the console says that approximately 150ms passed before the code even starts doing anything with the get request. However when I use 'http.get' the delay is less than <5ms.
My question is, what exactly is causing this 150ms delay and is there anyway to reduce it? Im sure that it is not ssl handshaking because this delay happens even when I input a non-existant website. It would be great if it was possible to code something earlier in the program so that when I execute a https.get() request, it would not have such a long startup time.
来源:https://stackoverflow.com/questions/27372129/150ms-delay-in-performing-a-https-versus-http-get-request-in-node