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

Provide easy configuration for limiting resource (mainly CPU) usage? #96

Closed
devonestes opened this issue Jan 14, 2020 · 12 comments · Fixed by #437
Closed

Provide easy configuration for limiting resource (mainly CPU) usage? #96

devonestes opened this issue Jan 14, 2020 · 12 comments · Fixed by #437
Labels
help wanted Extra attention is needed

Comments

@devonestes
Copy link

Environment

  • Elixir & Erlang versions (elixir --version): 1.9.2
  • Operating system: Linux Mint 19
  • Client (editor or IDE): Vim

I installed Elixir-LS a little bit ago, and I've noticed that it is a very resource intensive program. Since I usually leave vim open while doing other things, it will chew up a lot of CPU, making my computer relatively slow.

I was able to remedy this by editing the startup script to restrict the number of schedulers so that it was never taking up too much of my machine (now 2 cores out of the 8 available with elixir --erl "+S 2:2" -e "ElixirLS.LanguageServer.CLI.main()"), but I'm betting most Elixir users won't know how to do this, and it might affect their experience.

Maybe it would be nice if there was a way to let users easily configure how much of their machine's CPU they want Elixir-LS to have access to?

@binaryseed
Copy link

I've noticed memory usage can skyrocket which leads to swap & can bring the whole computer to a crawl.

@axelson
Copy link
Member

axelson commented Jan 15, 2020

@binaryseed are you also using the master branch? Could your issue be related to elixir-lsp/elixir_sense#67 if you're still running into an issue after updating (you need at least #87) then please raise a separate issue.

@devonestes I do think that would be a good idea. Have you noticed any considerable performance impact of the server with those settings? Also do you have a link to the documentation of those settings?

@binaryseed
Copy link

I'm running the latest master now and haven't seen memory explosion yet, so that's good news...

@binaryseed
Copy link

Also those flags are documented here:

+S Schedulers:SchedulerOnline

It can be configured during runtime too:

:erlang.system_flag(:schedulers_online, 2)

@devonestes
Copy link
Author

@axelson yes, this did help with my issues. The great thing about the BEAM is that it can efficiently use all your CPU cores, but that’s not really a property you want in a program running all the time on your personal/work computer because it starves out your other running programs - especially when it does meaningful work when it’s not actually in the “foreground,” unlike the hundred Chrome tabs most folks have open at any given time which are effectively idle in the background (unless they’re on a site like Slack or something).

There hasn’t been a noticeable impact on the performance of Elixir-LS itself. At least I haven’t noticed it. I’m sure some things are slower, but for me this has only made things better.

The easier thing to implement will probably be to have this configuration set with the system flag in the application boot, reading from a configuration file somewhere. That way it doesn’t need to pass arguments at boot, which will be easier for sure.

@axelson
Copy link
Member

axelson commented Jan 20, 2020

Okay that makes sense. I'll try this out locally to see how it runs/feels for me.

@lawik
Copy link

lawik commented Dec 7, 2020

Seems like this worked for me, preliminary results are that it did not implode on a large project getting a lot of dependencies updated:

in ~/.config/elixir_ls/setup.sh

#!/bin/bash

export ERL_FLAGS="$ERL_FLAGS +S 2:2"

Or it did nothing and I just didn't trigger dialyzer enough :)

@lawik
Copy link

lawik commented Dec 8, 2020

So what would y'all think about using something like getconf _NPROCESSORS_ONLN to get the number of processors and if >2 use that amount -2 just to be polite on the users system.

I'm sure there's a way to hit Windows as well, getconf works for me on Mac and Linux.

I figure this should be a default. I've had quite a few experiences where ElixirLS just reserves my machine for a few minutes for something I wasn't even actively doing which isn't the best experience. So far the script above seems to have solved my problem on this machine.

@axelson
Copy link
Member

axelson commented Dec 11, 2020

Yeah I think that makes sense. Ideally we'd be able to change the schedulers after startup of the node (so we can support windows easily), but that doesn't seem possible.

@axelson
Copy link
Member

axelson commented Dec 11, 2020

Actually it is possible:

iex(1)> System.schedulers_online
12
iex(2)> :erlang.system_flag(:schedulers_online, 10)
12
iex(3)> System.schedulers_online
10

I think that should make this change very easy

axelson added a commit to axelson/elixir-ls that referenced this issue Dec 12, 2020
This will make ElixirLS less resource-intensive because it isn't
expected to be the only program running on the user's machine.

Fixes elixir-lsp#96
@axelson
Copy link
Member

axelson commented Dec 12, 2020

I've marked #437 as fixing this since it will improve the behavior by default and it is already configurable via ~/.config/elixir_ls/setup.sh, although in the future it would be nice to have a configuration setting for this, and if someone wants that they can file a new issue.

@lawik
Copy link

lawik commented Dec 12, 2020

So it looks like it'll default to not using all of them if you have a bunch. This is absolitely fantastic.

lukaszsamson pushed a commit that referenced this issue Dec 14, 2020
This will make ElixirLS less resource-intensive because it isn't
expected to be the only program running on the user's machine.

Fixes #96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants