rogach

rogach

Why recon reports 2 schedulers even though BEAM was supposedly started with 1?

I’ve explicitly set number of schedulers to 1 on IEX startup:

iex --erl "+S 1" -S mix
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>

However, when I try checking scheduler usage via recon library, it reports two schedulers:

iex(1)> :recon.scheduler_usage(1000)
[{1, 7.620530725717925e-4}, {2, 0.0}]

Why is that? Where does this second scheduler come from?

Marked As Solved

03juan

03juan

It’s reporting on the number of total schedulers that were active during the 1000ms timespan, including dirty_cpu_schedulers.

:recon.scheduler_usage/1 executes :erlang.statistics(:scheduler_wall_time), whose docs explain:

Only information about schedulers that are expected to handle CPU bound work is included in the return values from this function. […]

Normal schedulers will have scheduler identifiers in the range 1 =< SchedulerId =< erlang:system_info(schedulers). Dirty CPU schedulers will have scheduler identifiers in the range erlang:system_info(schedulers) < SchedulerId =< erlang:system_info(schedulers) + erlang:system_info(dirty_cpu_schedulers).

The +S 1 flag is setting the number of “normal” scheduler threads used by the emulator.

Scheduler threads online schedules Erlang processes and Erlang ports, and execute Erlang code and Erlang linked-in driver code

There will always be at least 1 each of

  • dirty cpu schedulers

    execute CPU-bound native functions, such as NIFs, linked-in driver code, and BIFs that cannot be managed cleanly by the normal emulator schedulers

  • dirty io schedulers

    execute I/O-bound native functions, such as NIFs and linked-in driver code, which cannot be managed cleanly by the normal emulator schedulers

Here’s how my 16-core system boots with the same scheduler flag.

$ iex --erl "+S 1"
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.2) - press Ctrl+C to exit (type h() ENTER for help)

iex(1)> :erlang.system_info(:schedulers)
1
iex(2)> :erlang.system_info(:dirty_cpu_schedulers)
1
iex(3)> :erlang.system_info(:dirty_io_schedulers)
10
iex(4)> :erlang.statistics(:microstate_accounting) |> Enum.map(& {&1.type, &1.id}) |> Enum.sort()
[
  async: 0,
  aux: 1,
  dirty_cpu_scheduler: 1,
  dirty_io_scheduler: 1,
  dirty_io_scheduler: 2,
  dirty_io_scheduler: 3,
  dirty_io_scheduler: 4,
  dirty_io_scheduler: 5,
  dirty_io_scheduler: 6,
  dirty_io_scheduler: 7,
  dirty_io_scheduler: 8,
  dirty_io_scheduler: 9,
  dirty_io_scheduler: 10,
  poll: 0,
  scheduler: 1
]

By the way, that’s the info the BEAM prints out at the start [smp:1:1] [ds:1:1:10], equivalent to the flags iex --erl "+S 1:1 +SDcpu 1:1 +SDio 10"

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement