Vinay Pothnis
10/22/2021, 4:59 PMktor-client
and the best practices around it.
1. Whats the right way to re-use connections (or use a connection pool) with CIOEngine
? I am using the following configs:
engine {
maxConnectionsCount = 250
pipelining = true
endpoint {
maxConnectionsPerRoute = 100
pipelineMaxSize = 20
keepAliveTime = 5000
connectTimeout = 5000
connectAttempts = 5
threadsCount = 20
}
}
It looks like without the pipielining = true
flag, new connections were being created for every request/call.
Are these sufficient or is there any other config that I would need to set to effectively re-use connections?
2. Whats the recommended way to use client.close()
or client.use {}
- Especially when we are sharing/re-using the HttpClient
I went through the docs here - https://ktor.io/docs/client.html#close-client
With a shared HttpClient
- if I used client.use {}
- i was seeing errors on subsequent requests after some initial successful requests.
Errors like - kotlinx.coroutines.JobCancellationException: Parent job is Completed; job=JobImpl{Completed}@5e4f8454
So, when should this actually be used? During shutdown to release/cleanup the resources?
Thanks so much for your help with this!Aleksei Tirman [JB]
10/25/2021, 8:43 AMuse
extension function just executes the block and then closes a client. So if you want to share a client make sure to close it after making all necessary requests.Vinay Pothnis
10/25/2021, 4:17 PMAndroid
in the docs. Can this be used for JVM (non Android) as well?
I see that Jetty Engine only supports Http2.
So, that leaves only the Apache Engine. I wasn’t sure if that supported connection pooling. (At least it wasn’t evident from the docs)
Wondering what would be your recommendation for a production ready engine that can support connection pooling/reuse?Aleksei Tirman [JB]
10/25/2021, 5:34 PMWondering what would be your recommendation for a production ready engine that can support connection pooling/reuse?I don't actually know. @e5l could you please help with advice?
Vinay Pothnis
10/25/2021, 5:35 PMOkHttp engine could be used for JVM (non Android).Thanks @Aleksei Tirman [JB]!
e5l
10/25/2021, 5:36 PMVinay Pothnis
10/25/2021, 5:37 PMLucas Milotich
10/27/2021, 2:13 PM