150ms delay in performing a HTTPS versus HTTP get request in Node

China☆狼群 提交于 2019-11-28 12:19:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!