6

I'm running experiments on a node with 2 x Quad-Core Xeon E5520 2.2GHz, 24.0GB RAM, and Erlang R15B02 (SMP enabled). I wonder if I can limit the number of cores used by the Erlang VM so that I can temporarily disable some cores and increase the number step by step in order to test scalability.

I don't have root access on this node. So I'm expecting some method which is either by specifying parameters to erl or by Erlang code.

2240
  • 1,547
  • 2
  • 12
  • 30
Xiao Jia
  • 4,169
  • 2
  • 29
  • 47

1 Answers1

14

You can limit the number of cores Erlang uses via the +S option to erl, which allows you to set the number of scheduler kernel threads Erlang creates. See the erl man page for more details.

Note that Erlang linked-in port drivers and native implemented functions (NIFs) can both create their own threads and thus affect how many cores an Erlang process will use independently of the threads specified via the +S option, though none of the standard drivers or NIFs do this. Also the +A option to erl creates a pool of asynchronous threads for use by drivers that could also affect the number of cores used, and by default the async thread pool has 10 threads (it was empty by default prior to Erlang/OTP version R16B).

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
  • Thanks! Could you please explain the difference between `+S 4:2` and `+S 2:2` (i.e. `Schedulers` is greater than `SchedulerOnline`)? – Xiao Jia Nov 11 '12 at 16:07
  • 1
    `+S 2:2` means you want two schedulers and you want both of them online. `+S 4:2` means you want four schedulers but you want only two of them online. Note also that at runtime your application can examine and change the number of schedulers and online schedulers via the `erlang:system_info/1` and `erlang:system_flag/2` functions; see the documentation for [system_info/1](http://www.erlang.org/doc/man/erlang.html#system_info-1) and [system_flag/2](http://www.erlang.org/doc/man/erlang.html#system_flag-2) for more details. – Steve Vinoski Nov 11 '12 at 20:44
  • But since the number of online schedulers are the same, what's the effect of different `Schedulers` values? – Xiao Jia Nov 12 '12 at 00:01
  • 2
    My previous comment is a bit misleading, so it might be the cause of your confusion. It should say that `erlang:system_info/1` allows you to examine both the number of schedulers and the number of online schedulers, and `erlang:system_flag/2` allows you to change the number of online schedulers. Those two numbers are different: the number of schedulers is the max number available within your run of the Erlang VM and is fixed at startup. The number of online schedulers can range from 1 to the number of schedulers; you change it via `erlang:system_flag/2`. By default the numbers are the same. – Steve Vinoski Nov 12 '12 at 04:06
  • 1
    Note that in 2013 I submitted a patch, accepted for Erlang/OTP version R16B02 (released in September 2013), to add a `+SP` option to `erl`. This option allows you to set the number of schedulers and schedulers online by percentage rather than by absolute numbers. For example, `+SP 75:50` on a 24-core system sets the number of schedulers to 18 (75% of 24) and the number of schedulers online to 12 (50% of 24). See [the erl man page](http://erlang.org/doc/man/erl.html) for details. – Steve Vinoski Jan 21 '14 at 02:56