Search code examples
erlangelixirmessage-passing

Sending big lists between processes in Erlang / Elixir


Suppose you want to send a big list (1_000_000 entries for example) to a different process in Erlang / Elixir.

  • Does send block until the data of the whole list is sent, or is that somehow done asynchronously by the Erlang VM?
  • Is simply sending the list a bad practice? What are the alternatives?

Solution

    • Yes and no. Copying of huge structure doesn't block receiver but sender. See my answer to a similar question.
    • Yes, it is bad practice if you do it regularly. Alternatively:
      1. Refactor your code so you could partition data to different processes.
      2. Store data in ets. (It's not a magic bullet, you still copy data in and out of ets but it depends on your access pattern.)
      3. Store data as binary.

    It depends on what do you do. You should not have a big heap in a process so probably you should refactor your code.