erlang 如何解释为Supervisor重启策略指定的名称?

0ejtzxu1  于 2022-12-08  发布在  Erlang
关注(0)|答案(2)|浏览(168)

OTP管理员重启策略的名字对我来说似乎很奇怪,也许是因为我不是一个以英语为母语的人。

  • one_for_one:当一个子进程死亡时,将重新启动该子进程
  • one_for_all:当一个子进程死亡时,它将杀死所有其他子进程并按顺序重新启动它们
  • rest_for_one:当一个子进程死亡时,它将杀死在该死亡子进程之后引导的所有子进程,并按顺序重新启动它们

我试着通过把这些策略名称读成句子来理解它们,例如"重新开始one孩子forone孩子的死亡"。
那么one_for_allrest_for_one对我来说似乎是一个颠倒的名字。
为什么这些策略会这样命名?
c.f. erlang docs one_for_all部分有一个数字写着"多对一监督"。这只是一个错别字吗?

eqzww0vc

eqzww0vc1#

There are:

strategy() = one_for_all
               | one_for_one
               | rest_for_one
               | simple_one_for_one

I will skip simple_one_for_one and focus on the other three.
I believe the names for the restarts strategies are derived from the English idiom "One for all, all for one". The expression appears to be quite old .
one_for_one : meaning one goes and is replaced by a newly started child process.
one_for_all : meaning (from the idiom) that if one terminates then we (children) all terminate and start again.
rest_for_one : if one goes down then the rest also terminates, and starts up again. The "rest" in this case is referring to all the succeeding (behind) children in the start order specified. Note that the only difference between this and the one above is respecting the start order.
I prefer to think of them as a "single" strategy (ie one_for_one ) and a "full" strategy (ie one_for_all and rest_for_one ). In most cases this will work just fine.

xfyts7mz

xfyts7mz2#

"因为当所有人都为一,它是一为所有人。"布赖恩亚当斯或三个火枪手
因此,当一个服务器出现故障时,您可以重新启动所有服务器,或者当一个服务器出现故障时,重新启动其余服务器

相关问题