What do you do when you need a high performance collaborative state in Erlang?

Erlang did a great job of not sharing the fortune. But what happens when you want to have a general condition? For example: configuration parameters, statistics collection, event / callback servers. Creating new processes with some record as a state or using a process dictionary is a way to achieve a general state. You will loop this process over and over and reply to any messages. Several processes will simply request this process, using essentially the impure getter and setter functions that wrap the message passing, but here we just turned Erlang into an impure object that is slower than the java object due to the recovery system being replaced slower than just a memory mutex around each global state. It even has the ability to overflow a mailbox,if we are not careful.

So what do you do if you want a fast shared state? Reddis, database, mnesia, spwns looping state? How to make centralized state more pure functional in erlang?

+4
source share
1 answer

Use the public (someone can read or write) or protect (one writer, several readers) ets tables created with the option named_table. Each process that needs access to the general state in the table can get its name in the table.

+6
source

Source: https://habr.com/ru/post/1608168/


All Articles