문제

"monitor_node"라는 프로세스의 계층 구조가 있습니다. 이들 각각의 monitor_nodes는 하나의 수퍼바이저에 의해 감독됩니다. 이제, 이들 각각의 노드들은 복잡한 내부 구조를 가질 수있다. 의미, 즉 적절하게 작동하는 데 필요한 서브 프로세스가있을 수 있습니다 (또는 그렇지 않음). 예 : Process revence keep-alive 메시지. 지금까지는 일반 spawn_link를 사용하여 이러한 "내부"를 만듭니다. 프로세스.

그러나 Monitor_Node의 init 기능에서 그들을 산란시키는 것은이 함수가 실패 할 때 때로는이 함수가 실패합니다 (따라서 전체 감독자 트리가 실패 함). 내 질문은 다음과 같습니다.이 내부 프로세스를 감독자 나무에 첨부하는 것이 좋은 해결책이 될 것입니까? 나는 그것이 내부 프로세스를 감독하는 감독자에게 monitor_node를 변경하는 것에 대해 생각하고 있습니다.

의심은 다음과 같습니다 :

  1. 매우 상당한 수의 매우 작은 프로세스를 감독해야합니다. 이것이 좋은 실습인지 확실하지 않습니다.

  2. 나는 "내부"프로세스가 간단한 프로세스이거나 내부 구조 (다른 프로세스를 산란하게)가 있다는 사실을 미리 알지 못할 수도 있습니다. 후자가 사례 인 경우,이 "내부"프로세스를 감독자 트리에 첨부해야합니다.

    나는 당신을 너무 많이 혼란스럽지 않기를 바랍니다. 답변을 기대합니다.

    편집 :

    매우 유사합니다 (동일하지 않은 경우) 문제가 여기에 설명합니다 (3 포스트). 주어진 솔루션은 내가 쓰레기 대답을주는 것과 거의 같습니다.

도움이 되었습니까?

해결책

Supervisors:

There is a trick here, which includes the use of two supervisors. Your tree goes like:

main_sup -> worker
main_sup -> attached_pool_sup

attached_pool_sup -> workers

main sup is one_for_all, so if the worker or the pool supervisor dies, then the tree is done for and killed off. The pool supervisor is a simple_one_for_one which are suitable for having hundreds or thousands of workers.

Init:

Don't do too much work in your init callback. The supervisor will wait until the init completes and you can set a timeout (which you can increase in your case) if it takes longer than normal.

A trick is to quickly timeout (return with a timeout of 0 from init) and then handle additional setup in the handle_info timeout callback. That way you won't be stopping up the main supervisor. Beware of races here!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top