Why does ktor create a new dispatcher on okhttp? ...
# ktor
p
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
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
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
Could you try setting
clientCacheSize
to
1
in
OkHttpConfig
?