avli / clojureVSCode

Clojure support for Visual Studio Code
https://avli.github.io/clojureVSCode/
MIT License
204 stars 34 forks source link

CPU usage ~25% #56

Closed dijkstrah closed 6 years ago

dijkstrah commented 7 years ago

After NRepl started, while idle in the editor, java.exe CPU usage hovers around 25% with the August 1 version of the extension. Killing Visual Studio Code results in zombie java.exe which must be killed seperately.

Windows 10 1703 build 15063.540 Visual Studio Code: version 1.15.0 Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Please advise on how to troubleshoot.

avli commented 7 years ago

Thank you for raising this issue, I made a fix for this. Please upgrade to the latest version of the extension and let me know if the issue has gone.

dijkstrah commented 7 years ago

The issue has gone, and so has all functionality. After updating I observe the following behaviour:

Upon selecting a clojure file, "starting nREPL" message appears, then a separate windows console is started with a clojure repl. "starting nREPL" message doesn't go away, none of the extension's functions seem to work.

I would think the repl should be embedded in the visual studio code window?

avli commented 7 years ago

I have restored the previous behavior so you could use the stuff that worked previously. It seems like troubleshooting the issue will need a bit closer look than I expected.

@fachammer You mentioned about the detached option for the spawn in Windows in your pull request. I think that the detached option set to false causes the zombie Java process. Maybe you have any ideas?

fachammer commented 7 years ago

@avli Ok, so I looked into it and found out that no matter what the detached option, the java processes persisted after closing vscode. The problem seems to be that on Windows the lein command isn't started directly, but instead it is passed as an argument to the cmd.exe which then executes the lein repl. This means that lein is a "grandchild" process of vscode.

When closing vscode, somehow only the cmd.exe that spawned the lein process is closed and not its child processes. Other people seem to have the same problem. The solution on this SO question suggests to execute the taskkill command when on Windows (instead of process.kill). This gets rid of all child and grandchild processes.

I've implemented that solution and it seems to work. All the java processes are gone after closing vscode. I've opened a pull request #58

avli commented 7 years ago

@fachammer Great job! Thank you very much for your efforts!

avli commented 7 years ago

@dijkstrah I've just published the new release with the fix described above. Could you check it and confirm that the issue has gone?

dijkstrah commented 7 years ago

Hi, I have checked the fix. sorry for the delay. The Java process does not persist after closing Visual Studio Code editor. The issue that remains is the CPU usage of 25% while the application is sitting idle.

avli commented 7 years ago

@dijkstrah could you try to run the following command (maybe you'll need to adjust it slightly to run on Windows) and check how much CPU does it use?

lein update-in :dependencies conj [org.clojure/tools.nrepl "0.2.12" :exclusions [org.clojure/clojure]] -- update-in :dependencies conj [cljfmt "0.5.7"] -- update-in :plugins conj [refactor-nrepl "2.3.0-SNAPSHOT"] -- update-in :plugins conj [cider/cider-nrepl "0.15.0-SNAPSHOT"] -- repl
dijkstrah commented 7 years ago

Actually, on windows it is the following command. lein update-in ":dependencies" "conj" "[org.clojure/tools.nrepl \"0.2.12\" :exclusions [org.clojure/clojure]]" "--" "update-in" ":dependencies" "conj" "[cljfmt \"0.5.7\"]" "--" "update-in" ":plugins" "conj" "[refactor-nrepl \"2.3.0-SNAPSHOT\"]" "--" "update-in" ":plugins" "conj" "[cider/cider-nrepl \"0.15.0-SNAPSHOT\"]" "--" "repl"

After reaching the prompt, the cpu usage of java.exe hovers around 0.01 and 0.02 %.

gc87 commented 7 years ago

Hi @avli I have same problem on windows 10. VSCode: 1.18.1 clojureVSCode: v0.9.1 image

ak621 commented 6 years ago

lein repl :headless seems resolves this

avli commented 6 years ago

@ak621 that's awesome to hear! Have you tried this option for the embedded nREPL?

ak621 commented 6 years ago

Yes, after adding :headless to lein args in nreplController.js, JavaVM CPU usage decreased to ~0%, before it was ~30%. Windows 10.0.14393 (64-bit), Leiningen 2.8.1, Java 1.8.0_51 (32-bit)

martinbertolino commented 6 years ago

I can confirm also that the :headless option at the end of the lein command line, addresses the high CPU usage issue. I tracked it down to the thread that is trying to read from the console.

I'm wondering if the command line and arguments for lein in general should be a configuration parameters of sorts rather than being hardcode in the .ts source.

In that way users can have more flexibility in launching the process and controlling the parameters.

If there is interest in this approach, I would be willing on working on the feature and submitting a patch.

Thank you.

avli commented 6 years ago

@ak621 after adding the :headless option to the controller is the nREPL process killed after you close VSCode?

martinbertolino commented 6 years ago

Yes, it is. I tested a few times and the process java processes are gone (both the lein parent one and the clojure child one). I also captured process lists for validation.

See attached files for details. before-clj-ext.txt after-clj-ext.txt after-exit-vscode.txt vscode-clojure-ext.pdf

avli commented 6 years ago

The :headless option was added in the 0.9.4 release. Please report any issues with CPU consumption if any.

gc87 commented 6 years ago

It's all normal with me. CPU usage is 0%,Thank you:)

martinbertolino commented 6 years ago

Looks good for me as well on Windows 10. I will be validating on MacOS as well to make sure there are no regressions there. Thank you.

image

avli commented 6 years ago

@martinbertolino yes, do it if it's no bother. Everything seems to be fine on my Mac, but it's better to check twice.

Any Linux guys here by the way?

I'm going to close the issue now. If you discover any CPU consumption related issues, please reopen the issue and thanks everybody for debugging!

martinbertolino commented 6 years ago

I have checked on my Mac as well. Simple lein project REPL launched, no issues, works as expected.