节点http.get模块:是套接字开放事件,更准确地考虑在计算http请求的响应时间时将其视为开始时间
我正在使用节点HTTP模块并行测试100个端点。这些端点中的每一个都来自组织内的不同端点(不同的域),我想计算它们的TCP连接时间和总响应时间。 请在下面找到我的代码。由于节点JS正在单个事件循环中处理所有这些端点,因此我知道时间将通过多个请求共享。但是,在我启动计时器的时间(请参阅选项1)与节点正在处理其他回调的连接的实际打开之间是否存在差距。我想知道是否应该在打开插座后开始时间(选项2),因为这是HTTP生命周期中的第一步,端点响应时间可能从那里开始。 请建议。我正在尝试获得每个端点的最准确时间。
// **Option 1:** Start time before http.get (my current code)
var startTime = new Date();
var req = http.get(endpoint);
req.on('socket', socket => {
// **Option 2:** Start time when socket is open (Is this more accurate?)
var startTime = new Date()
socket.on('connect', () => {
var tcpConnectionAt = new Date();
console.log("TCP connection time: " + (tcpConnectionAt-startTime));
});
});
I am using node http module for testing 100 endpoints in parallel. Each of these endpoints are from different endpoints within my organization (different domains) and I want to calculate tcp connection time and total response time for them.
Please find my code below. Since node JS is processing all these endpoints in a single event loop, I understand that time will be shared by multiple requests. However, Is there a gap between the time at which I start timer (See Option 1) and actual opening of connection where node is processing other callbacks. I am wondering if I should start time once socket is open (Option 2) because that is the first step in HTTP lifecycle and endpoint response time should probably start from there.
Please advice. I am trying to get the most accurate timings of each of the endpoints.
// **Option 1:** Start time before http.get (my current code)
var startTime = new Date();
var req = http.get(endpoint);
req.on('socket', socket => {
// **Option 2:** Start time when socket is open (Is this more accurate?)
var startTime = new Date()
socket.on('connect', () => {
var tcpConnectionAt = new Date();
console.log("TCP connection time: " + (tcpConnectionAt-startTime));
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论