Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Stray Julia process with high CPU and RAM usage #4834

Open
jpmvferreira opened this issue Oct 12, 2023 · 2 comments
Open

[BUG] Stray Julia process with high CPU and RAM usage #4834

jpmvferreira opened this issue Oct 12, 2023 · 2 comments
Labels

Comments

@jpmvferreira
Copy link

Details

Trying to create an animation in Julia using notebooks on VS Code, causes high CPU and RAM usage. This bug takes place when restarting and re-running a cell which creates said notebook.

Reproducing the bug

I have found a way to reproduce this bug, at least on my machine, where the steps are:

  1. Create a new Jupyter notebook file and open it in a new VS Code session;
  2. Write the following piece of code in a single cell;
using Plots
anim = @animate for i=1:10
    plot()
    for n=0:2
        plot!(rand(3), rand(3), label="n = $n")
    end
end
mp4(anim)
  1. Run the cell, wait for it to finish, restart the kernel and run the cell again;
  2. Save and close the notebook when it finishes running;
  3. There should be now a stray Julia process in running in the background at 100% CPU usage on a single core, as well as two temporary directory managed by Julia, in /tmp/jl_*, that weren’t cleaned up. Closing VS Code will not free any resources.

Fortunately, I have found a workaround.
If instead of the previous block of code, you explicitly display the video and cleanup all files and variables, with, e.g.

using Plots
anim = @animate for i=1:10
    plot()
    for n=0:2
        plot!(rand(3), rand(3), label="n = $n")
    end
end

# store the video in a temporary directory and embed it in this notebook
tempdir = mktempdir()
video = mp4(anim, "$tempdir/output.mp4", fps=32)
display(video)

# remove the video and the animation object because the video is now embedded in this notebook
rm(anim.dir, recursive=true)
rm(tempdir, recursive=true)
anim = nothing
GC.gc()

then you are able of running and re-running the notebook without leaving stray Julia processes.
However, sometimes, there are still leftover directories that aren't cleaned up. I think this takes place whenever an animation fails at some point and my cleanup code doesn't run.

Now that I am here, does anybody happens to know an easier and boiler-plate free way of embedding the video directly into your Jupyter notebook on VS Code?
I rarely ever want to save the video to disk, because this way the notebook can be completely self-contained and easily shared with others without having to worry about carrying additional files.
I think having this option by default, as it is the default when you output plots, for example, would be very convenient and better incorporate the philosophy of the notebook.

Backends

This bug occurs on

Backend yes no untested
gr (default) x
pythonplot x
plotlyjs x
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots.jl version: v1.38.17
Backend version: GR v0.72.9
Output of versioninfo():

Julia Version 1.9.3
Commit bed2cd540a1 (2023-08-24 14:43 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 1 on 4 virtual cores
@jpmvferreira
Copy link
Author

I would like to note that although the output reports only one single thread being, as is the case in the notebook in VS Code, the mp4 function seems to somehow make use of all of my cores, at least temporarily.
I'm unsure if this is intended, or even relevant.

@BioTurboNick
Copy link
Member

Part of what you may be seeing the result of encoding the video with FFMPEG under the hood. Encoding video is very resource intensive. The animation code also works by saving frames to disk and then compiling them into a video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants