When will the pull request: https://github.com/dispatch/reboot/pull/118 be pulled to master?

57 visningar
Hoppa till det första olästa meddelandet

Hui Li

oläst,
18 juli 2016 09:43:352016-07-18
till Dispatch
Hello,

We are using Dispatch.Http in our application. Because of the security changes, we need to set the tls version in Http client(Http.configure(_ setSSLContext(...))), but this can cause the resource leak based on the pull request above.

Thanks,
Hui

Devon Miller

oläst,
18 juli 2016 11:19:072016-07-18
till Dispatch

Does calling shutdown on the provided Http instance address this problem?

Hui Li

oläst,
18 juli 2016 12:36:132016-07-18
till Dispatch
Maybe we can call client.shutdown(). But we use Http.client heavily(every second  at least hundreds if not thousands http calls), does it impact performance greatly since every call we have to create a new instance and shut down it after? 

Thanks,
Hui

Devon Miller

oläst,
18 juli 2016 14:16:522016-07-18
till Dispatch
I don't think you need to create a new Http client instance each time you want to make a single call. That actually sounds a bit heavy on resource allocation. Each thread could probably use their own client in the worst case, or each actor, if your client calls are running on an actor system. Akka http uses a pool underneath for the connections and caches them based on the target URL so that when you need a connection, you get one that was used to that destination before, and hence, configured for it.

If you still want to use a different Http client for each call, why not use a pool?

Then close all the client's down at program end.

Hui Li

oläst,
18 juli 2016 15:42:532016-07-18
till Dispatch
You are right, we don't want to create a new instance for each call. Here is my code which is using dispatch.Http:

---
trait DispatchHttpClientComponent {

def dispatchClient: Http

}

trait DefaultDispatchHttpClientComponentImpl extends DispatchHttpClientComponent {

lazy val dispatchClient = Http.configure(_.setSSLContext({
val ctx = javax.net.ssl.SSLContext.getInstance("TLSv1.1")
ctx
}))
} ----

So, every time when we make a http call using dispatchClient object, it will not create a new instance, right? I may misunderstand the pull request I mentioned above, I thought it always create a new instance since it is using 'configure' builder.

Devon Miller

oläst,
18 juli 2016 16:25:182016-07-18
till Dispatch
With the val, that code does *not* look like it creates a new instance each time you call it, unless you create an object with this trait for each call you make :-)

It *does* create a new instance for each instance of an object that implements that trait. It is derived from the base Http client which is included in the dispatch library.

If the DefaultDispatchHttpClientComponentImpl is placed on an object that is created thousands of times, you would have thousands of clients which is probably not needed.

Depending on how you configure the underlying async-http-client, you may not need as many "clients" as one client could send out and receive many requests.

Hui Li

oläst,
18 juli 2016 17:11:522016-07-18
till Dispatch
The DefaultDispatchHttpClientComponentImpl is only created once per application, we are using Cake pattern, so we only have one client per application.

Thank you very much! I really appreciate your timely answer,

Hui
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden