3 ms·
FUD, long running NIFs won't crash your VM, just block scheduler cores and mess up the real-time-y-ness of your application.
by wcummings 9y ago
FUD, long running NIFs won't crash your VM, just block scheduler cores and mess up the real-time-y-ness of your application.
- yellowapple 9y agoPorts are the conventional option for long-running native code, but I don't really know the performance implications.
- wcummings 9y agoPorts are more about communicating with and managing the lifecycle of external processes in a structured way, if I understand correctly (I have lots of experience with NIFs and next to none with ports). It's not quite a FFI. In the context of NIFs, long running could mean 100ms. The NIF API supports threads so you can always pass work to a thread pool and only block the scheduler thread for as long as it takes to acquire the lock on your queue. Or use dirty NIFs which I think are no longer experimental. There's also a new-ish function you can use to "yield" back to Erlang from a NIF but that kinda makes me nervous.