Ever increasing time for garbage collection

Hello,
I have a simulation that is running in real-time for an undefined period of time (until you stop it).
I solve my equation system every 50ms. For one solution about 800 calls to the inner residual function are needed. This works fine.

The problem I have is that the time needed for the garbage collection is continuously increasing.
joystick

I do an incremental garbage collection once per time step like this:

t_gc_tot = @elapsed GC.gc(false)

After 300s of simulation time already 12ms time are needed for the garbage collection, and if you extrapolate after 1200s the simulation will fail because most of the time is used for gc.

What can I do to solve this issue?

I have zero allocations in my simulation code, but the solver (IDA solver from Sundials with GMRES linear solver) is allocating a lot.

That’s really not supposed to happen. If you get a mwe that reproduces the behavior, it would be good to have it in GitHub - JuliaCI/GCBenchmarks

If you check out this repository: GitHub - aenarete/KiteViewers.jl: 3D viewer for airborne wind energy systems
And then execute:

include("examples/depower_simple.jl")

you get a plot where you can already see the increasing gc time…

But without active control you cannot run the simulation longer than 50s. If you have a joystick you can control the kite and run:

include("examples/joystick.jl")

which I did to produce the example in the last post.

But for a nice MWE I would need an autopilot which might be ready in a week…

2 Likes

It would be important to understand if the amount of memory stays constant or also increases evermore. The GC should only increase as function of heap_size and object-graph size. So this sounds like something is allocating more and more, but never releasing any of that memory,

2 Likes

I can try to disable the Makie based GUI and see if the problem persists…

How can I measure the memory that is used from within Julia?

Did you maybe hit this:

https://github.com/JuliaLang/julia/issues/45068

No, I did not turn GC off in my test…

Then I would look into is it also deallocating a lot (and look at max. mem. used, somehow).

I.e. I would look into if you’re using it wrong, or even if it has a bug. I suppose the underlying C code is ok.

I did look up e.g. Alloc, free, malloc (only found some constants that way), in the wrapper, and found some matches for all.

Do you need to do something with handles?

I’m not sure what this default early_free = false is, but likely a false alarm: