KTOR-如何为JVM平台选择客户引擎?
我们有JVM(JDK 8),并将OKHTTP用作开发人员的客户端引擎。每次提出请求时,最终创建并关闭了客户端的新实例。
在加载测试期间,我们偶尔会变得不寻常“ io.ktor.client.features.httprequesttimeoutexception:请求超时已过期”,而请求超时已配置为30秒。服务httpclient的服务没有绩效问题,并在当时的60毫秒内返回了其他请求。
可能怎么了?我们可以将OKHTTP用作JVM平台的客户端引擎吗?我们在JVM平台应该使用的最佳引擎是什么?非常感谢您的帮助!
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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论