0
votes

I want to be able to spawn a lot of processes that process data and fit them into a supervision tree. However all default behaviours, namely gen_server, gen_fsm, and gen_event, are event-driven. They have to receive messages to do stuff. What I need are just processes that process data, and in case they terminate abnormally, they should be restarted by their supervisor. What's the best way to go about doing this?

1
How do you mean "process data"? From where do they get their data and how is their execution controlled?rvirding
did you look at the supervisor behavior?Pascal
@rvirding The way I designed it was to store all data in ETS tables and start those worker processes with the keys to the tables. Then they will just lookup the table, get data, and process it. If they die in the meantime, they should be restarted by their supervisor, which potentially implements the supervisor behaviour.Derek Chiang
@Pascal yeah of course. what's your suggestion?Derek Chiang
But how are the worker processes controlled? Do they just run at full-speed when started until they die, or are they responsive to "outside" inputs.rvirding

1 Answers

1
votes

Yes, the standard behaviours all function as servers in that they sit and wait for requests before they do something. However, OTP is open in the sense that it provides the tools you need to implement processes which are not behaviours but which fit into the supervision trees and do "the right thing". For a description on what needs to be done and how to do it see the section on Special processes in the Erlang documentation.

This is really not surprising as all of OTP behaviours are implemented in Erlang so all the "tools" are there in the libraries.