OTP管理员重启策略的名字对我来说似乎很奇怪,也许是因为我不是一个以英语为母语的人。
one_for_one
:当一个子进程死亡时,将重新启动该子进程one_for_all
:当一个子进程死亡时,它将杀死所有其他子进程并按顺序重新启动它们rest_for_one
:当一个子进程死亡时,它将杀死在该死亡子进程之后引导的所有子进程,并按顺序重新启动它们
我试着通过把这些策略名称读成句子来理解它们,例如"重新开始one
孩子for
one
孩子的死亡"。
那么one_for_all
或rest_for_one
对我来说似乎是一个颠倒的名字。
为什么这些策略会这样命名?
c.f. erlang docs one_for_all
部分有一个数字写着"多对一监督"。这只是一个错别字吗?
2条答案
按热度按时间eqzww0vc1#
There are:
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 (ieone_for_all
andrest_for_one
). In most cases this will work just fine.xfyts7mz2#
"因为当所有人都为一,它是一为所有人。"布赖恩亚当斯或三个火枪手
因此,当一个服务器出现故障时,您可以重新启动所有服务器,或者当一个服务器出现故障时,重新启动其余服务器