Node.js的响应时间 [英] Node.JS Response Time

查看:262
本文介绍了Node.js的响应时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

扔在一个AWS实例的Node.js和被测试的要求时,得到了一些有趣的结果。

Threw Node.JS on an AWS instance and was testing the request times, got some interesting results.

我用下面的服务器:

var http = require('http');

http.createServer(function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.write('Hello World');
  res.end();
}).listen(8080);

我有一个平均90毫秒延迟到这台服务器,但总的要求采取〜350 + MS。显然大量的时间被浪费在盒子上。我确定DNS在测试前被缓存。

I have an average 90ms delay to this server, but the total request takes ~350+ms. Obviously a lot of time is wasted on the box. I made sure the DNS was cached prior to the test.

我的服务器1000 cocurrency上做了一个Apache板凳 - 它完成了10,000个请求4.3秒......这意味着平均4.3毫秒

I did an Apache bench on the server with a cocurrency of 1000 - it finished 10,000 requests in 4.3 seconds... which means an average of 4.3 milliseconds.

更新:只是为了笑着,我安装在同一台机器上的Apache + PHP,做一个简单的Hello World的回声,并得到了92ms的响应时间,平均(二过平)

有一个设置的地方,我很想念?

Is there a setting somewhere that I am missing?

推荐答案

我绝对讨厌回答我的问题,我要传我已经发现了未来的读者。

I absolutely hate answering my own questions, but I want to pass along what I have discovered with future readers.

TL;博士:有什么不对的res.write()。使用EX press.js或res.end()

我只是通过进行一系列测试了。我设置多种类型的节点服务器的混合的东西,如PHP和Nginx的。这里是我的发现。

I just got through conducting a bunch of tests. I setup multiple types of Node server and mixed in things like PHP and Nginx. Here are my findings.

正如previously,与我包括上面的片段中,我失去了周围250毫秒/请求,但Apache的基准并没有复制的问题。我接着做一个PHP的测试并得到了结果,从2毫秒 - 20毫秒以上平...有很大的区别

As stated previously, with the snippet I included above, I was loosing around 250ms/request, but the Apache benchmarks did not replicate that issues. I then proceeded to do a PHP test and got results ranging from 2ms - 20ms over ping... a big difference.

这促使一些更多的研究,我开始的Nginx服务器并通过它代理的节点,并以某种方式,奇迹般地改变了回应,从250毫秒到15毫秒过平。我看齐的PHP脚本,但是这确实是一个令人困惑的结果。通常额外跳会慢下来。

This prompted some more research, I started a Nginx server and proxied the node through it, and somehow, that magically changed the response from 250ms to 15ms over ping. I was on par with that PHP script, but that is a really confusing result. Usually additional hops would slow things down.

出于好奇,我做了一个前press.js服务器,以及 - 和一些更有趣的事情发生了,平了2ms的超过自己。我在源周围挖了很长一段时间,发现它缺乏一个 res.write()命令,相反,它直奔水库.END()。我开始另一台服务器从 res.write 取出的Hello World,并把它添加到 res.end 和不可思议的是,平是在0毫秒平。

Intrigued, I made an express.js server as well - and something even more interesting happened, the ping was 2ms over on its own. I dug around in the source for quite a while and noticed that it lacked a res.write() command, rather, it went straight to the res.end(). I started another server removing the "Hello World" from the res.write and added it to the res.end and amazingly, the ping was 0ms over ping.

我做了这方面的一些搜索,想看看它是否是一个众所周知的问题,遇到此等问题,谁拥有完全相同的问题。 nodejs的响应速度和nginx的

I did some searching on this, wanted to see if it was a well-known issue and came across this SO question, who had the exact same problem. nodejs response speed and nginx

总体而言,intresting东西。确保你优化你的反应,这一次全部发送。

Overall, intresting stuff. Make sure you optimize your responses and send it all at once.

祝您好运给大家!

这篇关于Node.js的响应时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆