When implementing a system that requires performance, we sometimes use NIFs, a mechanism for calling higher-performance C code from Elixir. NIFs perform better than Port, another mechanism to call C. However, they have the disadvantage that if they crash, the entire Erlang VM will be abnormally terminated, even under Supervisor’s control. This defect is a significant obstacle when building fault-tolerant systems.
This talk shows three points to describe robust NIFs:
- Appropriately set a conditional branch where each function call may return an uncertain value.
- Perform error handling according to general conventions.
- Make assertions that specify implicit preconditions and raise exceptions for Supervisor to handle. This talk also shows how to improve performance even with such robustness and fault tolerance and build NIFs for various platforms.
- Present that NIFs are mechanisms for calling higher-performance C code from Elixir.
- Also, present that though Supervisor realizes fault tolerance, ordinal NIFs hinder it.
- Provide three tips on enabling Supervisor to achieve fault tolerance even with NIFs.
- Anyone who has interested in how to describe NIFs with fault-tolerance.