[erlang-questions] how: Purging old records from Mnesia table

Gleb Peregud gleber.p@REDACTED
Thu Mar 6 12:38:25 CET 2008


I would like to implement some algorithm of purging old data from
mnesia table. Expiration date is written inside each record (could be
0 for permanent data).

I have few ideas how to implement it:
0) Every few seconds iterate over whole table and purge old records.
It is implemented in this way now and it eats about 35% of CPU on
every purge cycle for about 10 000 entries.
Will index on expiration field speed up selecting? Is it better to use
qlc? Will it speed give speed up if i use mnesia:index_match_object()

1) Use erlang:send_after() to send messages to purge individual
records (with special care to timeouts greater then max value of
unsigned int). Will Erlang runtime handle efficiently potentially up
to few millions of timers?

2) Use some sort of queue to manage sorted list of records to be
purged. Make special process which will receive information about new
records, insert into this queue and sleep until first record is to be
purged. Probably gb_trees will handle it. Are there better ADS for
this task?

I'll be greateful for any advices and responses :)

Best Regards,
Gleb Peregud

More information about the erlang-questions mailing list