LoginSignup
10
9

More than 5 years have passed since last update.

supervisorとapplicationが停止する条件

Posted at

supervisorとapplicationが停止する条件

ドキュメントをちゃんと読んでいれば, 当然知っているであろうことなのですが, 「セグフォも吐いてないのに何か死んでる!!」と焦ったことがあるので, 自分への戒めとして投稿します.

supervisorの終了条件

To prevent a supervisor from getting into an infinite loop of child process terminations and restarts, a maximum restart intensity is defined using two integer values specified with the intensity and period keys in the above map. Assuming the values MaxR for intensity and MaxT for period, then if more than MaxR restarts occur within MaxT seconds, the supervisor will terminate all child processes and then itself. The default value for intensity is 1, and the default value for period is 5.

とあるように, 子プロセスの再起動限界を超えた場合, 全ての子プロセスを殺した後に自分自身も終了する
言われてみれば, 再起動限界を超えたということは, 正しく動かないということなのでsupervisorごと死ぬのは当然といえば当然である.

transientやpermanentを指定する場合は, 再起動限界を超えた場合の挙動も意識する必要がありそうだ.

OTPの実装

OTPの実装としては以下の箇所が該当する.

applicationの終了条件

If a permanent application terminates, all other applications and the entire Erlang node are also terminated.
If a transient application terminates with Reason == normal, this is reported but no other applications are terminated. If a transient application terminates abnormally, all other applications and the entire Erlang node are also terminated.
If a temporary application terminates, this is reported but no other applications are terminated.

runningのapplicationが死んだ時, 再起動戦略的に再起動しなければいけない場合applicationが終了する

依存関係のあるapplicationが終了した場合は正しく機能しなくなる訳だから, よく出来ている.
あまりapplicationの再起動戦略を選択する余地はなさそうだが, そのapplicationがなくても動作するようなもの (例えば動作確認用に使うapplicationのようなもの) はtemporaryにして, それ以外はpermanentにするなどの選択はできそうだ.

ちなみに, applicationのrestart_typeはapplication:start/2で指定することができる.
また, 現在起動中のapplicationの情報はapplication:info/0で見ることができる.

OTPの実装

OTPの実装としては以下の箇所が該当する.


ドキュメントはちゃんと読みましょう.

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9