Hello KTor Team!
I wanted to check with on couple of things related to
ktor-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!