Question

Are these methods system_info and system_flag make a system call to the Operating system each time I call one of them? Or are they use stored values of Erlang virtual machine?

Task: I'm writing an application which checks the idling processors and create new processes to complete a task. If these methods are doing a system call, it can be a performance overhead.

Was it helpful?

Solution 2

The functions system_info and system_flag are BIF's which make calls to the c code found in the file erl_bif_info.c , this code is not a NIF so calling them will not cause problems in the sense that long running NIFs might.

NIFs are considered harmful

  • Long-running NIFs will take over a scheduler and prevent Erlang from efficiently handling many processes.
  • Short-running NIFs will still confuse the scheduler if they take more than a few microseconds to run.

A crashing NIF will take down your VM.

OTHER TIPS

The functions erlang:system_info and erlang:system_flag inspect and work on the Erlang virtual machine and not the underlying OS. They allow you to inspect the system to see how it is performing and in some ways to control it. The BEAM, the erlang virtual machine, is a complex beast and there is a lot of information to be had. Another useful function is process_info which allows you to get information about one process.

While these functions are obviously written in C you can be certain that calling them will not casue problems in the sense that long running NIFs might. Long-running in the case means more than milliseconds. Also important is how often they are called and whether by the same process etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top