在AWS实例上抛出Node.JS并测试请求时间,得到了一些有趣的结果.
我在服务器上使用了以下内容:
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('Hello World');
res.end();
}).listen(8080);
Run Code Online (Sandbox Code Playgroud)
我对此服务器的延迟平均为90毫秒,但总请求大约需要350 + ms.显然,很多时间浪费在盒子上.我确保在测试之前缓存了DNS.
我在服务器上做了一个apocurrency 1000的Apache工作台 - 它在4.3秒内完成了10,000个请求...这意味着平均4.3毫秒.
更新:只是为了笑容,我在同一台机器上安装了Apache + PHP并做了一个简单的"Hello World"回音并且平均得到了92ms的响应时间(两次超过ping).
我错过了什么地方?
刚开始测试nodejs,并希望在理解以下行为方面获得一些帮助:
var http = require('http');
http.createServer(function(req, res){
res.writeHeader(200, {'Content-Type': 'text/plain'});
res.end('foo');
}).listen(1001, '0.0.0.0');
Run Code Online (Sandbox Code Playgroud)
var http = require('http');
http.createServer(function(req, res){
res.writeHeader(200, {'Content-Type': 'text/plain'});
res.write('foo');
res.end('bar');
}).listen(1001, '0.0.0.0');
Run Code Online (Sandbox Code Playgroud)
在Chrome中测试响应时间时:
示例#1 - 6-10ms
示例#2 - 200-220ms
但是,如果通过nginx proxy_pass测试这两个例子
server{
listen 1011;
location / {
proxy_pass http://127.0.0.1:1001;
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
示例#1 - 4-8ms
示例#2 - 4-8ms
我不是nodejs或nginx的专家,并询问是否有人可以解释这个?
nodejs - v.0.8.1
nginx - v.1.2.2
感谢Hippo,我使用和不使用nginx在我的服务器上进行了测试,结果相反.
还添加到nginx配置proxy_cache关闭
server{
listen 1011;
location / {
proxy_pass http://127.0.0.1:1001;
proxy_cache off;
}
}
Run Code Online (Sandbox Code Playgroud)
ab -n 1000 …