Node.js 响应时间 >= 200ms?
我正在进行 Node.js 工作负载测试,刚刚遇到了一个有趣的行为。 HTTP 服务器的最小响应时间是 200 毫秒,即使对于最简单的逻辑也是如此:
var http = require("http");
http.createServer(function(request, response) {
response.write("Hello World");
response.end();
}).listen(8080);
在 Windows Server 2003 上运行:
> node main.js
我搜索了网络,但没有找到任何有关此的信息。测试是在本地网络上完成的,此外,使用其他网络服务器(即IIS)我可以实现即时响应时间。不要误会我的意思,我看到了这种行为背后的合理解释,所以这是我的问题:
这是 Node.js 附带的默认行为,还是可能是其他原因的结果?
按需说明:
- Node js 版本:0.6.11
- 操作系统:Windows Server 2003 R2 SP2
- 服务器环境:VMWare Workstation 8.0.0
- 工作负载实用程序:jMeter 2.6(1 线程工作负载)
更新
延迟行为仅在远程请求期间出现。如果执行本地工作负载测试,延迟将接近于零。但是,这不可能是网络延迟问题,因为针对同一服务器上的 IIS 的远程请求不会产生延迟。我将在其他操作系统上尝试一下。
I am working on a Node.js workload test and I have just encountered an interesting behavior. The minimum response time of an HTTP server is 200 ms, even for simplest logic:
var http = require("http");
http.createServer(function(request, response) {
response.write("Hello World");
response.end();
}).listen(8080);
Ran on Windows Server 2003:
> node main.js
I searched the web, but have not found any information about this. The test is done on local network, furthermore with the use of other webserver (namely IIS) I can achieve instant response time. Don't get me wrong, I see rational explanation behind this behavior, so this is my question:
Is this the default behavior coming with node.js, or could it be the result of something else?
Clarification on demand:
- Node js version: 0.6.11
- OS: Windows Server 2003 R2 SP2
- Server environment: VMWare Workstation 8.0.0
- Workload utility: jMeter 2.6 (1 thread workload)
Update
The delay behavior only appear during remote requests. If a local workload test is executed, the latency will be close to zero. However, it cannot be a network latency issue, because a remote request against IIS on the same server does not give latency. I am going to try this out on other OSes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它是 Windows 上默认设置的 Nagle 算法(也可以在 Azure 上的 Windows 2008 R2 上重现)。
解决方法 - 在响应套接字上禁用它,如下所示:
It is Nagle algorithm set by default on Windows (reproducible also on Windows 2008 R2 on Azure).
Workaround - disable it on response socket, like this:
此处延迟 5 毫秒,下载 3 毫秒,总共 8 毫秒。
它有所不同,但我见过的最高总时间约为 14 毫秒。
不过在 OS X 10.7.3 上运行。我得在 Windows 上试试看。
Getting 5ms latency, 3ms download for a total of 8ms here.
It varies but the highest I've seen is about 14ms total.
Ran on OS X 10.7.3 though. I will have to try on Windows and see.
我运行的是 Ubuntu 64 位和节点版本 0.6.10,最多有 20 毫秒的延迟。我相信这是一个Windows问题,因为Node在Windows上仍然不完美,必须等待更多的稳定性。我建议您将您的问题发布到邮件列表中。
I'm running Ubuntu 64bit and node version 0.6.10 and at most I get a 20ms delay. I believe it is a windows problem, since Node is still not perfect on windows, have to wait for some more stability. I suggest you to post your problems to the mailing list.