I think there is a memory leak either in julia or in HTTP.jl

I have a web application that loads a trained model and then basically queries this model and shows result in handwritten html only using HTTP.jl no other web frameworks. Training the model goes fine as far a memory is concerned. It’s when I use the weba pplication that after a while memory keeps increasing until I’ve reached max memory (16 GB and then the GC struggles to bring the memory down. It does bring it down somewhat but never by big amounts and never back to the level of when the app started and the application becomes very slow.

So I suspect there is a problem either with julia memory management itself or with HTTP.jl.
This is my setup:
Windows 10 (up to date)
julia 1.6.1
HTTP 0.9.0

The application itself is run within the terminal of VSCode 1.60.2 (with latest julia plugin).

Anyone else experienced similar problems? I tried google julia 1.6 memory leak but didn’t find much.

Have you checked that there are no global variables that keeps building up or something? The varinfo function can perhaps help you identify this (e.g. varinfo(Main) or varinfo(MyModule) etc).

3 Likes

hmmm now that you say this. I do have a session var to track server side state… Might be the culprit. I’ll have to investigate.

Well it’s not my session.

Perhaps it is a response handler implementation issue. If memory is allocated repeteadly when responding to requests, this may cause GC problems.

Unfortunately, without code or an example of what you’re doing, it’s kind of hard to give any actionable advise or try to track down an issue in julia or HTTP.jl.

Maybe there’s some vector you’re continously growing to larger and larger sizes?

1 Like

Relatively sure it isn’t HTTP, since we’re using that without any problems in our application.

I’d try to replicate the issue with the model alone, removing HTTP from the stack.

I’ve done some further testing and I’m pretty sure there is an actual problem with the combination HTTP.jl & julia runtime.

As long as you have a low request rate where the response comes before the next request there is no problem, but if the requests come faster than the response (e.g. by clicking very fast on submit button) then memory grows and doesn’t really come down much afterwards.

It probably has to do with background tasks/multithreading & GC. I’ve seen a bug related to that in julia as recent as julia 1.3 Large memory leak when using threads · Issue #31923 · JuliaLang/julia · GitHub but apparently that was fixed but maybe there is still a related problem in julia.

My experience is that HTTP.jl can handle thousands of requests / second (using tested using ab) with no leaking. Also, the requests were returning data and calling some pretty complex logic.

Unless you can find the bug / memory leak and reproduce it in another program/MWE, assume the error is on your side. It will help your hopes high on solving your problem and others from seeking an potentially non-existing bug.