[Question] CPU 100% Apache Ktor Http Client
See original GitHub issueKtor Version
1.1.3
Ktor Engine Used(client or server and name)
Apache
JVM Version, Operating System and Relevant Context
Feedback
I utilize ktor http client to communicating from service to other service, but after 10 minutes deployment my machine experience CPU 100%, any idea why ?
here’s the building block that I use,
override fun sendAsync(request: HttpRequest, responseCallback: Callback<HttpResponse>) {
GlobalScope.launch (Dispatchers.IO + CoroutineName(key ?: "")) {
try {
decorateRequest(request)
val requestUrl = URL(request.url)
val requestBody = String(request.body.asArray(), StandardCharsets.UTF_8)
val requestMethod = HttpMethod(request.method)
val requestContentType = createContentType(request)
val clientResponse = httpClient!!.request<io.ktor.client.response.HttpResponse>{
method = requestMethod
url(requestUrl)
body = TextContent(requestBody, requestContentType)
request.headers.forEach {
if (!unsafeHeaderSet.contains(it.name)) {
header(it.name, it.value)
}
}
}
val response = HttpResponse()
val responseBodyString = String(clientResponse.readBytes())
response.statusCode = clientResponse.status.value
response.bodyEncoding = "UTF-8"
response.body = IndirectNIOBuffer(ByteBuffer.wrap(responseBodyString.toByteArray(charset("UTF-8"))), true)
clientResponse.headers.forEach { name, value ->
val headerValue = value.joinToString(",")
response.addHeader(name, headerValue)
}
clientResponse.close()
responseCallback.onComplete(response)
} catch (error: Exception) {
responseCallback.onException(error)
}
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (19 by maintainers)
Top Results From Across the Web
High CPU usage by Ktor-client-apache when Package ...
Hi. After half an hour of using the environment, the CPU is at 100% load. What I got from the Activity Monitor: %CPU...
Read more >Occasionally Ktor utilizes 100% CPU without any load after ...
Occasionally Ktor utilizes 100% CPU without any load after failed request.
Read more >Hi I got tons of ktor client apache threads when running a s - Kotlinlang
Hi , I got tons of “ktor-client-apache” threads when running a server. And in fact the server is not doing anything . Is...
Read more >Engines | Ktor
The Ktor HTTP client can be used on different platforms, including JVM, ... The Apache engine supports HTTP/1.1 and provides multiple ...
Read more >Performance for my Ktor web service (Profiling?) : r/Kotlin
I tried assigning a dedicated 2k thread pool to the Java 11 HttpClient, and it's gotten to the point where CPU%/100 is fairly...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@e5l @IRus
TLSv13
caused us a lot grief but as far as I can say all known issues have been resolved with HttpCore 4.4.12.Apache Client one of the most feature complete, and production tested clients. This issue related to the newest JDK releases and particularly TSL v1.3 support. Still, this https://github.com/ktorio/ktor/issues/1018#issuecomment-565648818 fixes issue