[英]Difference Between node.js HTTP Server, Request, and Response Timeouts
When it comes to timing out HTTP requests, it looks like node.js has three separate timeouts: 当谈到超时HTTP请求时,看起来node.js有三个单独的超时:
Can anyone clarify what the difference is between each of these methods and why someone would want to use each one? 任何人都可以澄清每种方法之间的差异以及为什么有人想要使用每种方法?
req.setTimeout
and res.setTimeout
ultimately result in the same underlying system call that sets the timeout on the TCP socket itself using the corresponding libuv/os calls. req.setTimeout
和res.setTimeout
最终导致相同的底层系统调用,它使用相应的libuv / os调用设置TCP套接字本身的超时。 So I think both are equivalent and you can you whichever one is more convenient or whichever one feels semantically clearer to you. Generally the defaults are reasonable. 通常默认值是合理的。 However, you might want to set these longer if you knew you had a lot of clients on very slow or flakey connections (you serve mobile phones in remote areas or satellites or whatever), and connections that were actually still viable we being closed due to timeout.
但是,如果您知道很多客户端的连接速度非常慢或很复杂(您在偏远地区或卫星或其他任何地方提供移动电话),并且实际上仍然可行的连接,我们可能需要设置更长时间超时。 You might want to set them shorter if you knew your clients were well-connected (like servers in the same datacenter), and you wanted to free up resources more aggressively.
如果您知道客户端连接良好(如同一数据中心中的服务器),并且您希望更积极地释放资源,则可能需要将它们设置得更短。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.