orzen / ertorrent

Other
5 stars 2 forks source link

Lifetime of a worker process #13

Open orzen opened 8 years ago

orzen commented 8 years ago

An OTP application contains a supervision tree design.

A supervision tree design contains a supervisor process that keeps track of a server process and another supervisor process, this supervisor is referred to, as the super supervisor (visualized below). The second supervisor will keep track of workers. The supervisor will spawn and terminate workers based on internal API calls to the server process.

o super supervisor |- server |- supervisor | |- worker X | |- worker Y

In cases where there are multiple processes depending on a certain worker's existence. It becomes relevant to have a life span that is implicitly controlled by these processes. This could be handled in multiple ways and therefore this discussion. An example where it is relevant within ertorrent is the handling of tracker worker processes. Multiple torrents might want to communicate with the same tracker, the tracker worker process can therefore not get killed off when one of the torrent processes consider itself to finished with the communication.

Two suggestions is reference counting and timeout.

A passive approach is timeout. When a process is needed it is spawned and it live as long as the depending processes is feeding it. When fed, the process will reset its timer. The risks with this approach is inefficiency and it's considered a fragile design. The fragile part is that the process risk to terminate when another process is about to feed it.

In my opinion the reference counting is more robust and won't leave processes alive and awaiting termination and therefore more efficient.

Thoughts and opinions?

olof commented 8 years ago

Nice writeup... Some comments and questions: