persistent_term to replace ETS for caching

Richard O'Keefe raoknz@REDACTED
Sun Dec 6 15:29:40 CET 2020

Thanks for that advice about persistent_term.
>From the documentation,
When a persistent term is updated or deleted, a global garbage collection
pass is run to scan all processes for the deleted term, and to copy it into
each process that still uses it.
Do I understand correctly that if three processes refer
to a persistent-term, and one of them deletes it, it
will be copied into both of the other processes, thus
INCREASING the amount of memory used?
This is sufficiently counter-intuitive that I am not
sure I would dare to use this feature.

Do I further understand correctly that *adding* a new
persistent-term does NOT force garbage collection?

On Mon, 7 Dec 2020 at 00:49, Nalin Ranjan <ranjanified@REDACTED> wrote:

> It has the potential to trigger Global GC, and can affect responsiveness
> as per the docs.
> Regards
> Nalin Ranjan
> On Sun, Dec 6, 2020 at 5:16 AM Frank Muller <frank.muller.erl@REDACTED>
> wrote:
>> Hi guys,
>> At work, we cache about 5.3 million entries in ETS. The system works
>> perfectly, no issue so far (many years).
>> During a brainstorming session, a colleague suggested to switch to
>> persistent_term instead to avoid ETS term copying.
>> Pretty simple: we check if the Key exists in persistent_term. If yes, we
>> are done. If not, we get it from ETS, move it to persistent_term and send
>> it back to the caller.
>> Question: is there any limitation(s) on persistent_term usage? Stated
>> otherwise, can we create 5.3 million persistent_term <K,V>?
>> Any suggestion/idea/thought is very welcome.
>> /Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list