https://kotlinlang.org logo
Title
p

Paul Woitaschek

02/23/2021, 5:03 PM
Why does ktor create a new dispatcher on okhttp? https://github.com/ktorio/ktor/blob/d7d1b65796a1b05f40a0d1d652b3c3f4e26351b2/ktor-client/ktor-client-okhttp/jvm/src/io/ktor/client/engine/okhttp/OkHttpEngine.kt#L146 Quoting jesse:
For most efficiency, you'll have one ConnectionPool​ and one Dispatcher in your process. These can be shared by many OkHttpClient instances.
https://github.com/square/okhttp/issues/3372#issuecomment-304830644
e

e5l

02/24/2021, 10:54 AM
Hey, @Paul Woitaschek. It’s done to allow independently close different instances of
OkHttp
engine. In other way you have to make sure that there are no other requests running by different instances of
OkHttp
in the same dispatcher before close.
Could you tell me if you have any problems with that?
p

Paul Woitaschek

02/24/2021, 10:56 AM
Im trying to keep exactly one instance of OkHttpClient in my project so I have as less threads running as possible so the connections and threads will be shared as much as possible
e

e5l

02/24/2021, 11:00 AM
Could you try setting
clientCacheSize
to
1
in
OkHttpConfig
?