【问题标题】:What is the difference between idle-timeout and request timeout in akka http configuration?akka http配置中的idle-timeout和request timeout有什么区别?
【发布时间】:2017-06-22 07:06:56
【问题描述】:

我查看了文档并找到了这些 # 空闲连接自动关闭的时间。 # 设置为infinite 以完全禁用空闲连接超时。 空闲超时 = 10 秒

# Defines the default time period within which the application has to
# produce an HttpResponse for any given HttpRequest it received.
# The timeout begins to run when the *end* of the request has been
# received, so even potentially long uploads can have a short timeout.
# Set to `infinite` to completely disable request timeout checking.
#
# If this setting is not `infinite` the HTTP server layer attaches a
# `Timeout-Access` header to the request, which enables programmatic
# customization of the timeout period and timeout response for each
# request individually.
request-timeout = 20 s

我的服务器需要超过 10 秒的时间来处理响应,但在发送 HTTPResponse 之前,客户端和服务器之间的 TCP 连接由于 空闲超时而超时。

虽然此时连接处于空闲状态,但请求仍在处理中。

我以为这是响应超时的责任?

在这种情况下,谁能解释一下空闲超时和响应超时之间的区别?

【问题讨论】:

    标签: scala akka-http connection-timeout


    【解决方案1】:

    文档有点混乱,我已经在此基础上进行了实验:

    idle-timeout:这是连接可以处于空闲状态的最长时间。它的行为与请求超时相同。示例:

    空闲超时 = 1 秒

    应用程序已向第 3 方 API 发送请求并建立连接,但第 3 方未响应。然后你会得到一个超时异常。

    “akka.stream.scaladsl.TcpIdleTimeoutException”

    connecting-timeout: 500 ms。 表示必须建立 Http 连接的最长时间(500 ms)。

    【讨论】:

      【解决方案2】:

      来自documentationmore details here

        # The idle timeout for an open connection after which it will be closed
        # Set to null or "infinite" to disable the timeout, but notice that this
        # is not encouraged since timeout are important mechanisms to protect your
        # servers from malicious attacks or programming mistakes.
        idleTimeout = 75 seconds
      

      如果您将空闲超时设置为低于请求超时,则优先。您的空闲超时设置应该比请求超时时间长,因此对于每个请求,请求超时决定何时关闭连接。

      【讨论】:

        猜你喜欢
        • 2018-07-14
        • 1970-01-01
        • 2013-06-22
        • 1970-01-01
        • 2016-05-08
        • 1970-01-01
        • 2017-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多