vptheron
vptheron

Reputation: 7466

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

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.

Upvotes: 1

Views: 889

Answers (2)

joliva
joliva

Reputation: 340

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

Upvotes: 1

Stefano Bonetti
Stefano Bonetti

Reputation: 9023

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))

Upvotes: 1

Related Questions