Distributed.jl icon indicating copy to clipboard operation
Distributed.jl copied to clipboard

need periodic distributed GC for quicker release of remote objects

Open bdqp opened this issue 10 years ago • 7 comments

Overwriting RemoteRef variables does not release memory.

Start Julia from bash: julia -p 2 Check memory: free -m (used = 7398) In Julia: r = remotecall(2, rand, 17000, 17000); Check memory: free -m (used = 9617)

Now overwrite r:

In Julia: r = remotecall(2, rand, 17000, 17000); Check memory: free -m (used = 11834) In Julia: gc() Check memory: free -m (used = 11814)

I would expect the overwritten r to have its memory released by the garbage collector.

bdqp avatar Jul 10 '15 10:07 bdqp

for i in 1:20
     r = remotecall(2, rand, 17000, 17000); 
     @everywhere gc()
end

completed without any issues on 0.3.9

The issue is that a RemoteRef is only the size of 3 ints, and till it is locally garbage collected, it does not send a "delete my reference to the stored value" message on worker 2. Forcing a gc everywhere is one way to ensure collection is done sooner than later - not an ideal solution, though.

amitmurthy avatar Jul 10 '15 12:07 amitmurthy

Hi Amit - I guess the point I was trying to make is that the memory used by processor 2 is not released automatically even after the reference to it no longer exists.

As you say, manually calling the gc() is not ideal but julia is not doing any gc for this situation otherwise.

bdqp avatar Jul 10 '15 13:07 bdqp

I concur. I was just trying to explain how the distributed gc is implemented. Local gc may not actually collect r if its size is too small. And the distributed gc is dependent on the finalizers on RemoteRef's being run in order for the remote value to be ultimately freed.

amitmurthy avatar Jul 10 '15 14:07 amitmurthy

Just a little follow up - sorry I'm learning as I go here :) The command below seems to suggest it will clean up memory.

take!(RemoteRef) Fetch the value of a remote reference, removing it so that the reference is empty again.

However, if I execute the following command several times the memory gets consumed until it runs out. I was expecting the memory consumed by the variable on worker 2 to be cleared.

tic(); tic(); r = remotecall(2, rand, 7000, 7000); toc(); f = take!(r); toc()

bdqp avatar Jul 29 '15 17:07 bdqp

Possibly related? https://groups.google.com/forum/#!topic/julia-users/0ab8qxTdVIg

sbromberger avatar Sep 06 '15 02:09 sbromberger

@amitmurthy I believe most of these issues are now fixed. Can we close this?

ViralBShah avatar Sep 09 '17 15:09 ViralBShah

No. While not a "leak", an explicit gc call still helps in an early release of the remote object.

amitmurthy avatar Sep 11 '17 07:09 amitmurthy