Should the mapping of Id in Pid be stored in the ets table or in the gen_server state?

I am creating an OTP application that follows a pattern similar to that described in trapexit , where I implement a non-blocking gen_server using gen_server:call/3 to initiate a transaction with a backend and keep the transaction id mapping from pid From . When gen_server receives a message from the backend, it retrieves the transaction ID and uses this mapping to find the correct pid that it sends to the message.

In the trapexit example, this mapping is implemented using ets, however, I found that having the gen_server state contains a dict with these mappings as a very natural solution.

In my particular use case, the display will contain no more than 200 entries.

Which implementation is recommended?

Thanks in advance!

+4
source share
2 answers

200 is enough to have some kind of performance impact over ets (probably an order of magnitude or less). The real question that you should ask yourself is: "Do I need this extra performance, or will that be enough?"

If performance is not a problem, use a dict.

+2
source

A functional approach is to keep personal data in a state. One practical consideration against having very large state data (which, in your opinion, does not look like) is that it will be dumped into the fault log.

0
source

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


All Articles