Hi I’m completely new to Elixir and Erlang. I was reading the documentation at https://elixir-lang.org/getting-started/introduction.html and was wondering about some details around processes which is the most interesting feature of Elixir (to me).
What are the patterns around dealing with busy processes? If calls to send can never block how can a sender detect if a process is busy? Is there a way to rate limit sender? What happens if the receiver never calls receive does memory just fill up?
Typically a process that is expected to receive heavy messages does not perform any work, instead it would spawn Tasks to handle each as it comes in. The current default limit for processes is 262144, and this is configurable. Use processes.
You would limit rates if and only if you are trying to access some critical resource, in which case put a buffer (bit-bucket / queue) in between. Usually this means using ets or mnesia or RabbitMQ as a holding area for messages.
Plus if a process’s mailbox is pretty full then it ‘slows’ down sending to it more and more the more full it is, so a process sending a message to it will be ‘back-pressured’. This doesn’t help if it’s a new process sending a new message every time but it helps throttle the system under most loads.
But ‘OTP’ is the main pattern used to manage processes, and there is a lot built up on it.
Even if this (e.g. a process in an infinite loop) happens, it will not immediately bring down your system, because of the pre-emptive scheduling of the BEAM VM.
You can easily see that a process is broken by using tools such as :observer whenever you are awake and looking at your system again, then figure out what is going on, fix it and hot-upgrade the system without causing any downtime.
I can really recommend the talk Solid Ground by Sasa Juric, where he gives more info, and live creates, introspects and fixes a ‘broken’ process!