https://kotlinlang.org logo
#ktor
Title
g

gotoOla

12/03/2018, 4:34 PM
anyone here that has a lot of experience with netty? We migrated a vertx+coroutine (kotlin 1.2.61-app) to ktor 1.0 and we are seeing some memory leakage. This is the visualvm images which I can’t really tell a lot from but the reason why I am asking about netty is the call-thread
Screenshot 2018-12-03 at 17.28.43.png
the heap histogram shows 52% char[] but I don’t really know what to expect when profiling/analyzing coroutines.
l

lukaswelte

12/03/2018, 5:47 PM
If you found the reason let us know here in the Thread 🙂
f

fred.deschenes

12/03/2018, 5:54 PM
not sure if it's doable with Ktor, but Netty has built-in leak detection stuff you can activate : https://netty.io/wiki/reference-counted-objects.html#wiki-h2-9
r

rocketraman

12/03/2018, 6:18 PM
I had some issues with ktor+netty as well, though a much earlier version of ktor. Didn't have time to debug so switched to a Jetty backend and all was well.
g

gotoOla

01/17/2019, 2:59 PM
One month later and now I can get back to you 😄 (forgot about this thread but I saw it in my “all threads” now) This wasn’t a problem with netty, we experienced the same thing with jetty. The problem was caused by the ktor-client which was used with the Apache Engine. We got a leakage when we did not close the response. I did not find any documentation about this but I got hold of one of the JetBrains guys who helped me out with this. So eventually it was solved by something like this:
Copy code
val response = <http://client.post|client.post><HttpResponse>("url") {...}
...
response.close()
r

rocketraman

01/17/2019, 3:11 PM
Or better:
Copy code
<http://client.post|client.post><HttpResponse>("url").use {...}
g

gotoOla

01/17/2019, 3:15 PM
@rocketraman thanks I have completely missed this!
we have a few extensions which does the close for us and report metrics for error-cases etc but I think this could still be valuable!
r

rocketraman

01/17/2019, 3:21 PM
Yes,
use
is one of those must-know Kotlin extensions -- it's Kotlin's equivalent of Java's try-with-resources.
👍 1
5 Views