Skip to content

Commit

Permalink
Don't use all of the available schedulers (elixir-editors#437)
Browse files Browse the repository at this point in the history
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-editors#96
  • Loading branch information
axelson committed Dec 14, 2020
1 parent 4932739 commit a696d94
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/elixir_ls_debugger/lib/debugger/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule ElixirLS.Debugger.CLI do
{:ok, _} = Application.ensure_all_started(:elixir_ls_debugger, :permanent)
IO.puts("Started ElixirLS debugger v#{Launch.debugger_version()}")
Launch.print_versions()
Launch.limit_num_schedulers()
warn_if_unsupported_version()
WireProtocol.stream_packets(&Server.receive_packet/1)
end
Expand Down
10 changes: 10 additions & 0 deletions apps/elixir_ls_utils/lib/launch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ defmodule ElixirLS.Utils.Launch do
get_version(:elixir_ls_debugger)
end

def limit_num_schedulers do
case System.schedulers_online() do
num_schedulers when num_schedulers >= 4 ->
:erlang.system_flag(:schedulers_online, num_schedulers - 2)

_ ->
:ok
end
end

defp get_version(app) do
case :application.get_key(app, :vsn) do
{:ok, version} -> List.to_string(version)
Expand Down
1 change: 1 addition & 0 deletions apps/language_server/lib/language_server/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule ElixirLS.LanguageServer.CLI do

IO.puts("Started ElixirLS v#{Launch.language_server_version()}")
Launch.print_versions()
Launch.limit_num_schedulers()

Mix.shell(ElixirLS.LanguageServer.MixShell)
# FIXME: Private API
Expand Down

0 comments on commit a696d94

Please sign in to comment.