Stray Julia processes (with high cpu usages)

Post High CPU Usage on Startup - VSCode OSX triggered my post. As the link mentions, the post was about "high-cpu-usage-on-startup-vscode-osx”. I responded but didn’t want to hijack that thread so deleted my post and decided to make it a separate post.

Since Julia 1.3 I have encountered many issues with stray/high cpu usage on Julia process. It should be said that this behavior is much more often observed in the many cases I run external programs (in my case cmdstan and GKSTerm).

I wonder if the high cpu usage is confined to vscode. I see similar issues with Sublime Text and TextMate once compilation of packages start. I don’t know if in vscode’s startup sequence compilation/package indexing might be triggered.

Also, is this behavior confined to OSX? Travis test runs often time out, occasionally while it is still resolving package versions. Could that be related?

On OSX, sometimes it takes many, many minutes before it returns and often it simply never returns (although I’m not sure I ever waited overnight :-). The Activity Monitor has become a goto tool…

A third issue I have seen is that the additional Julia processes indeed seem to persist after interrupting the REPL (sometimes much later on breaking in with an error message).

Finally, in many cases when I display a plot with Plots/GR Julia simply hangs. Even the REPL stops responding. The Julia process remains running. These days I only use Plots/GR where I use savefig() which prevents GKSTerm to be activated.

I see this on 1.3 and development versions 1.4 and 1.5. I don’t think I ever saw it before Julia 1.3.

It is unclear to me if these issues are related or separate issues.

Until last week I thought it was an issue with my machine, but now I’ve quadrupled memory, disk space and cores.

Is it worth filing an issue without a real MWE?

Isn’t it called macOS now?
This may be relevant, I mean: It may be relevant which exact version of macOS this happens.
Other macOS users ( I am not one) may post their similar or not experience and some patterns may show up.

1 Like

It would be good to know more

  1. about these processes, what exactly you mean by “stray” (eg output from pstree),

  2. the environment variables you use for setting the number of threads/parallell

An MWE would definitely be helpful, then running it with parallelization disabled, then finally in 1.2.

Possibly — comments from people could help you narrow it down. But coming up with some kind of script, even if not minimal, that reliably reproduces this on your machine would probably help a lot.

Definitely, macOS it is!

julia> versioninfo()
Julia Version 1.5.0-DEV.55
Commit ade4713598 (2020-01-13 12:50 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin19.3.0)
CPU: Intel(R) Core™ i9-9880H CPU @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = subl
JULIA_CMDSTAN_HOME = /Users/rob/Projects/StanSupport/cmdstan
JULIA_SVG_BROWSER = Google Chrome.app
JULIA_SPECIALFUNCTIONS_BUILD_SOURCE = true
JULIA_PKG3_PRECOMPILE = true

The problems have been there on Mojave as well. If in doubt if it is Julia’s under development version I always go back to the current released version of Julia (1.3.1 currently).

Without a MWE/reproducable example, the post is indeed intended to see if it is just my machine/me or if these are more common issues.

Look in macOS activity monitor for Julia processes that use a lot of cpu, then you can look what file they opened (in the “Open Files and Ports” tab) and check if you see something related to the language server.

Thanks Tamas,

I’ll keep on trying to come up with a reproducible example. Right now it is too much anecdotal. I’ll add another example on the StanRun issue.

And check out other suggestions on this post.

Just now it happened again. From Jonathans suggestions (PNGs below), it looks like it is in code-gen.

After several minutes the middle 2 processes went away.

This is the output of pstree:

Process group leaders are marked with ‘=’.
➜ ~ pstree -p 65845
-+= 00001 root /sbin/launchd
-+= 10662 rob /System/Applications/Utilities/Terminal.app/Contents/MacOS/Term
-+= 10664 root login -pf rob
-+= 10665 rob -zsh
-+= 65839 rob /Users/rob/Projects/Julia/julia/julia
-– 65845 rob /Users/rob/Projects/Julia/julia/usr/bin/julia -Cnative
➜ ~ pstree -p 65839
-+= 00001 root /sbin/launchd
-+= 10662 rob /System/Applications/Utilities/Terminal.app/Contents/MacOS/Term
-+= 10664 root login -pf rob
-+= 10665 rob -zsh
-+= 65839 rob /Users/rob/Projects/Julia/julia/julia
-– 65845 rob /Users/rob/Projects/Julia/julia/usr/bin/julia -Cnative

And it came back after 20 mins and completed the tests!

julia> versioninfo()
Julia Version 1.5.0-DEV.62
Commit 756891d910 (2020-01-14 06:58 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin19.3.0)
CPU: Intel(R) Core™ i9-9880H CPU @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = subl
JULIA_CMDSTAN_HOME = /Users/rob/Projects/StanSupport/cmdstan
JULIA_SVG_BROWSER = Google Chrome.app
JULIA_SPECIALFUNCTIONS_BUILD_SOURCE = true
JULIA_PKG3_PRECOMPILE = true

So this is a LanguageServer/VS Code issue?

1 Like

Maybe. I’m not sure what the open port to julia-codegen really means.

But, as often is the case, just asking a question helped. For a long time (7 years already!?!) I used a few definitions like below (importing Base.* of course):

  function *(c1::Cmd, c2::Cmd)
    res = deepcopy(c1)
    for i in 1:length(c2.exec)
      push!(res.exec, c2.exec[i])
    end
    res
  end

  function *(c1::Cmd, sa::Array{String, 1})
    res = deepcopy(c1)
    for i in 1:length(sa)
      push!(res.exec, sa[i])
    end
    res
  end

  function *(c1::Cmd, s::String)
    res = deepcopy(c1)
    push!(res.exec, s)
    res
  end

and this I think is no longer possible in Julia 1.3 and higher. No error is shown but compilations don’t (ever?) return.

I used these to build a run CmdStan in all of StanJulia/… and in JagsJulia/Jags.jl. I have removed them from StanJulia but not from Jags yet.

Both on my system and on Travis this has made a huge difference for StanJulia.

Jags might provide a reproducible case in fact. Developing Jags.jl should install Jags and ] test Jags hangs my system, currently on Julia Version 1.5.0-DEV.70 (2020-01-15) on macOS Catalina.

It would be of great help if you could confirm my suspicion. Luckily the work around is easy, using cmd interpolations instead to *.

As always, thanks for your (and others) help!

And yes, it did come back again in the end, after about 30 mins. The tests then run until it misses Random and sits quiet for a really long time. The second pause is ok, that’s my error, must have started between Julia 1.2 and 1.3.

Just now I did rebuild Julia and was able to reproduce the ‘issue’ (very long pre-compile time). After my next build of Julia dev I will try without above constructs in master.

Just for completeness, below a case where Julia did not come back for several hours.

Julia Version 1.5.0-DEV.104
Commit 372a7a726d (2020-01-18 18:35 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin19.3.0)
CPU: Intel(R) Core™ i9-9880H CPU @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = subl
JULIA_CMDSTAN_HOME = /Users/rob/Projects/StanSupport/cmdstan
JULIA_SVG_BROWSER = Google Chrome.app
JULIA_SPECIALFUNCTIONS_BUILD_SOURCE = true
JULIA_PKG3_PRECOMPILE = true

i will put my two cents and bet that it is the language server of the VSCode Plugin. it takes a lot of time to index the packages (variable, but over half an hour), and when its doing that, it takes a lot of resources.

2 Likes

I do have VS Code on my system but have not used it for several months. I use Sublime Text.

My next step is to work for a few days just on J1.3.1 two see if that reduces these very long (re-)compiles from admittedly dev-ed, but unchanged packages.

Not sure at all if my interpretation of the Open files and ports is correct, but when Julia appears to hang very often the last file open points to the repl_history.jl. Not in the cases where it came back after 10 or 15 minutes though.

Every time it causes high CPU usage, I close it, the process seems to be endless. So, I should wait for it to end?

Any updates on this issue. I notice similar Julia stray processes on M1 Mac with Julia 1.7

1 Like