Akka-http - configuration of request and host-level pools

不羁岁月 提交于 2020-06-13 06:11:09

问题


What is the relationship in terms of pool settings between the super-pool used by the Request-level API, and the cached pool created by the host-level API?

To provide more context: I need to query the same host/endpoint with fast, responsive requests, and with more expensive requests. My current strategy is to use Http().singleRequest() for the cheap queries, and a cached host-pool to "isolate" the more expensive queries. I want to make sure that the expensive queries won't use up all the connections available in the super-pool.

Am I right in my expectation that they will indeed be 2 separate pools even though they point to the same host? If so, is there a way to configure, say the max-connection count, for the super pool and for the cached pool separately? I only see one setting in the reference.conf file.


回答1:


I believe if you don't specify different configurations, Akka-HTTP will cache the underlying pool and share it. This holds for both Http().singleRequest(...) and Http().cachedHostConnectionPool(...) calls.

If you want different pools, the trick is to provide different configurations, as the docs state:

Note that, if you request pools with different configurations for the same target host you will get independent pools.

Both singleRequest and cachedHostConnectionPool calls take an optional settings: ConnectionPoolSettings parameter. You can create this from the default one and tweak the params you want to tweak, e.g.

Http().cachedHostConnectionPool("localhost", 80, ConnectionPoolSettings(system).withMaxConnections(2000))



回答2:


As @Stefano Bonetti say, the easy workaround for this is to force akka-http use different cached pools by configuration, for example if you use singleRequest() api you can change the user-agent and then akka create diferent pools for you, a code example in java can be:

 UserAgent userAgent =  UserAgent.create(ProductVersion.create("akka-http", "1.0", actorPath));

    ConnectionPoolSettings setting = ConnectionPoolSettings.create(context().system())
            .withConnectionSettings(ClientConnectionSettings.create(context().system())
            .withUserAgentHeader(Optional.of(userAgent)));


    http.singleRequest(httpRequest, http.defaultClientHttpsContext(), setting, context().system().log(), materializer).... Here code to handle the response


来源:https://stackoverflow.com/questions/45201230/akka-http-configuration-of-request-and-host-level-pools

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!