Are Erlang/OTP messages reliable? Can messages be duplicated?

前端 未结 3 1421
-上瘾入骨i
-上瘾入骨i 2021-01-30 00:57

Long version:

I\'m new to erlang, and considering using it for a scalable architecture. I\'ve found many proponents of the platform touting its reliabi

3条回答
  •  天涯浪人
    2021-01-30 01:28

    The erlang OTP system is fault tolerant. That doesn't relieve you of the need to build equally fault tolerant apps in it. If you use erlang and OTP then there are a few things you can rely on.

    1. When a process dies that process will be restarted.
    2. For the most part a process crashing won't bring down your whole app
    3. When a message is sent it will be received provided the receiver exists.

    As far as I know messages in erlang are not subject to duplication. If you send a message and the process receives it then the message is gone from the queue. However if you send a message and the process receives that message but crashes while processing it then that message is gone and unhandled. That fact should be considered in the design of your system. OTP helps you handle all of this by using processes to isolate infrastructure critical code (eg. supervisors, gen_servers, ...) from application code that might be subject to crashes.

    For instance you might have a gen_server that dispatches work to a process pool. The processes in the pool might crash and get restarted. But the gen_server remains up since its entire purpose is just to recieve messages and dispatch them to the pool to work on. This allows the whole system to stay up despite errors and crashes in the pool and there is always something waiting for your message.

    Just because the system is fault tolerant doesn't mean your algorithm is.

提交回复
热议问题