'Ktor - how to choose client engine for JVM platform?
We have JVM (JDK 8) and used okhttp as client engine by developers. Each time we makes a request, a new instance of client is created and closed finally.
During load testing, we got occasionally unusual "io.ktor.client.features.HttpRequestTimeoutException: Request timeout has expired " while request timeout was configured 30 seconds. The service httpclient called had no performance issue and returned in about 60ms around that time to other requests.
What might be wrong? Can we use okhttp as client engine for JVM platform? What is the best engine we should use for JVM platform? Thank you so much for your help!
fun getClient() : HttpClient {
val httpClient = HttpClient() {
if (httpClientLogging) {
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.BODY
}
}
install(JsonFeature) {
serializer = KotlinxSerializer(KotlinJson {
isLenient = true
ignoreUnknownKeys = true
})
}
install(HttpTimeout) {
requestTimeoutMillis = 30000
connectTimeoutMillis = 30000
socketTimeoutMillis = 30000
}
}
return httpClient
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
