Reputation: 177
I have multiple Erlang VMs running on a Windows machine. I want to pre-allocate number of cpu cores to be used by each VM. For Instance VM1 should use only 2 cores, VM2 should use other 2 cores.
Please Help
Upvotes: 2
Views: 244
Reputation: 41598
The simplest thing to do is to tell the Erlang VM how many cores to use, using the +S
option:
erl +S 2
It's called S
because the Erlang VM uses one scheduler per core.
By default, the schedulers are not bound to any core. You can check that using erlang:system_info(scheduler_bindings)
:
3> erlang:system_info(scheduler_bindings).
{unbound,unbound}
You could ask the Erlang VM to bind the schedulers to cores by passing the arguments +sbt db
, but that would backfire if you run more than one VM on the same machine, as they would bind to the same cores. Thus you also need to use the +sct
option to use a custom CPU topology. First, figure out what the Erlang VM thinks the actual topology is. This is what it says about my laptop:
2> erlang:system_info({cpu_topology,detected}).
[{processor,[{core,[{thread,{logical,0}},
{thread,{logical,4}}]},
{core,[{thread,{logical,1}},{thread,{logical,5}}]},
{core,[{thread,{logical,2}},{thread,{logical,6}}]},
{core,[{thread,{logical,3}},{thread,{logical,7}}]}]}]
So let's bind the first VM to logical threads 0 and 4, being on thread 0 and 1 respectively, both on core 0 of processor 0:
erl +S 2 +sbt db +sct L0T0C0P0:L4T1C0P0
And let's bind the second VM to logical threads 1 and 5, on thread 0 and 1 of core 1 of processor 0:
erl +S 2 +sbt db +sct L1T0C1P0:L5T1C1P0
If you are using Elixir, you can pass all these options with with the --erl
argument to elixir
or iex
:
iex --erl "+S 2 +sbt db"
Upvotes: 3
Reputation: 2243
I would not recommend doing this as OS is probably the best guy to schedule the processes that can run efficiently on the CPUs and changing this might not really help (should be determined by performance benchmarking).
It cannot be done using Erlang VM flags alone. For windows specific look into this example
Following is the windows only command.
cmd.exe START /affinity 3 erl +S 2
cmd.exe START /affinity B erl +S 2
Affinity 3 (x0011) runs the Erlang VM OS process in CPU0 and 1 only. Affinity B (x1100) runs the Erlang VM OS process in CPU2 and 3 only.
erl +S 2 runs 2 scheduler threads that the OS can run on 2 CPUs. This would utilize the CPUs effecietly as running more might result in context switches and running less might result in under utilization of the resource
Upvotes: 3