我们目前正在将一个tomcat应用程序移植到spray / scala中。
我们的旧应用程序有这样的设置:
<Connector port="8082" protocol="HTTP/1.1"
maxThreads="1000"
maxConnections="10000"
processorCache="500"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />
在新的应用程序中,我们希望在喷涂中设置相当于maxThreads / maxConnections。
我看到了喷涂reference.conf文件(如下),我想知道这些是否确实是要更改的正确设置?
或者我应该配置正在执行runRoute的actor吗?
还是两个?
我确实找到了低&#34; max-connections = 4&#34;默认有点奇怪,如果那确实是服务器连接限制。
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}
}
答案 0 :(得分:4)
您所指的设置是喷涂客户端设置,而不是喷涂服务器设置。
host-connector { max-connections = 4 }
这意味着如果您想编写连接到某个外部HTTP服务器的喷涂应用程序,您将无法同时为特定主机创建4个以上的连接。
Spray中没有直接等效于 maxThreads / maxConnections 。因为Spray建立在Akka Actors之上。 Akka Actors使用Dispatchers和Execution Contexts来处理消息。 Spray for Http Listener(处理HTTP请求的actor)中的默认调度程序是:
listener-dispatcher = "akka.actor.default-dispatcher"
您可以阅读有关默认调度程序here
的信息没有直接的方法在Spray中指定 maxThreads ,因为默认的akka调度程序基于顶级 fork-join-executor ,它正在利用多核架构可能。
要指定 maxConnections ,您必须修改HttpListener的源代码:
case x: Tcp.Bound if(maxConnections()) ⇒ //handle max connections use case