【问题标题】:Setting spray connection limits设置喷雾连接限制
【发布时间】:2015-01-15 12:04:23
【问题描述】:

我们目前正在将一个 tomcat 应用程序移植到一个 spray/scala 应用程序。

我们的旧应用程序有这样的设置:

<Connector port="8082" protocol="HTTP/1.1"
        maxThreads="1000"
        maxConnections="10000"
        processorCache="500"
        connectionTimeout="20000"
        URIEncoding="UTF-8"
        redirectPort="8443" />

在新的应用程序中,我们希望在 spray 中设置 maxThreads/maxConnections 的等效项。

我看到了 spray reference.conf 文件(如下),我想知道这些是否确实是要更改的正确设置?
还是我应该配置正在执行 runRoute 的参与者?
还是两者都有?

我确实发现低“max-connections = 4”默认值有点奇怪,如果这确实是服务器连接限制的话。

host-connector {
# The maximum number of parallel connections that an `HttpHostConnector`
# is allowed to establish to a host. Must be greater than zero.
max-connections = 4

# The maximum number of times an `HttpHostConnector` attempts to repeat
# failed requests (if the request can be safely retried) before
# giving up and returning an error.
max-retries = 5

# Configures redirection following.
# If set to zero redirection responses will not be followed, i.e. they'll be returned to the user as is.
# If set to a value > zero redirection responses will be followed up to the given number of times.
# If the redirection chain is longer than the configured value the first redirection response that is
# is not followed anymore is returned to the user as is.
max-redirects = 0

# If this setting is enabled, the `HttpHostConnector` pipelines requests
# across connections, otherwise only one single request can be "open"
# on a particular HTTP connection.
pipelining = off

# The time after which an idle `HttpHostConnector` (without open
# connections) will automatically terminate itself.
# Set to `infinite` to completely disable idle timeouts.
idle-timeout = 30 s

# Modify to tweak client settings for this host-connector only.
client = ${spray.can.client}

}

【问题讨论】:

    标签: scala akka spray


    【解决方案1】:

    您所指的设置是喷涂客户端设置而不是喷涂服务器设置。

    host-connector {    max-connections = 4 }
    

    这意味着如果您想编写一个连接到某个外部 HTTP 服务器的喷雾应用程序,您将无法同时创建超过 4 个与特定主机的连接。

    Spray 中没有直接等效于 ma​​xThreads/ma​​xConnections 的方法。因为 Spray 是建立在 Akka Actors 之上的。 Akka Actors 使用 Dispatchers 和 Execution Contexts 来处理消息。 Spray for Http Listener(处理 HTTP 请求的参与者)中的默认调度程序是:

    listener-dispatcher = "akka.actor.default-dispatcher"
    

    您可以阅读默认调度程序here

    没有直接的方法在 Spray 中指定 ma​​xThreads,因为默认的 akka 调度程序基于顶级 fork-join-executor,它利用多核架构与可能的。

    要指定ma​​xConnections,你必须修改HttpListener的源代码:

    case x: Tcp.Bound if(maxConnections()) ⇒ //handle max connections use case
    

    【讨论】:

      猜你喜欢
      • 2011-02-23
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      相关资源
      最近更新 更多