4 ms·
Do nifs have the equal process time stuff that regular elixir processes have? Where the BEAM will move the scheduler into another process if it's taking too lon
by cooljacob204 2y ago
Do nifs have the equal process time stuff that regular elixir processes have? Where the BEAM will move the scheduler into another process if it's taking too long?
Forgive me if I'm mixing up my terminology it's been a bit since I have poked at Elixir.
- rubyn00bie 2y agoNope, at least not by default or like one would expect from pure Erlang (when it comes to preempting). Been a while since I dug into this admittedly but I write Elixir daily for work (and have for about ten years now). They don’t do the record keeping necessary for the BEAM to interrupt. You need to make sure the “dirty scheduler” is enabled or you can end up blocking other processes on the same scheduler. Here’s a link I found talking about using the dirty scheduler with Rust(ler): https://bgmarx.com/2018/08/15/using-dirty-schedulers-with-rustler/ https://bgmarx.com/2018/08/15/using-dirty-schedulers-with-ru...
- throwawaymaths 2y agoYou can write nifs that way but it seems like a pain in the ass https://www.erlang.org/doc/apps/erts/erl_nif#enif_schedule_nif https://www.erlang.org/doc/apps/erts/erl_nif#enif_schedule_n... After all, many of the BIFs have been replaced internally by NIFs And there's this, which would scare me: https://erlang.org/documentation/doc-15.0-rc3/erts-15.0/doc/html/automaticyieldingofccode.html#introduction https://erlang.org/documentation/doc-15.0-rc3/erts-15.0/doc/...
- b3orn 2y agoBEAM can't preempt native code, that's why NIFs should either be fast/low-latency to not excessively block the scheduler or be put in what's called a dirty scheduler which just means to run it in a separate thread.