[erlang-questions] Re: implementing a notification list

Martin DeMello <>
Fri Mar 19 13:14:09 CET 2010

Thanks, Steve. When searching I need to filter on the event type as
well as retrieving records within a range of timestamps, so I'll
probably have the timestamp as the pk and index on the event type.
What worried me was this post:

When we scaled this up, we discovered that we were doing
one or both of the following alot: 1) insert at the front or 2) delete
from the back.  Since the underlying implementation is trying to be a
balanced tree, this leads to alot of rebalancing, which slows things down
(doubly so since our ordered set was on disk). We switched to specialized
data structures at that point.

It seems to me that I'd be doing much the same thing, that is
inserting a series of timestamps in increasing order, which would
potentially lead to a lot of rebalancing of the tree. I don't want to
optimise prematurely, of course, but I also don't want to find out a
few months down the line that I've made the wrong decision and have to
face a potentially expensive ripping-out and reworking.


On Thu, Mar 18, 2010 at 9:07 PM, Steve Davis
<> wrote:
> HI Martin,
> A couple of approaches to consider for a starting point:
> 1) If appropriate you could use the timestamp as the key on your
> db_event record, i.e. -record(db_event, {timestamp, data, ...})
> 2) If using the timestamp as the key isn't appropriate, you can index
> the timestamp field, http://erlang.org/doc/apps/mnesia/Mnesia_chap5.html#id2273564
> hth,
> /s
> On Mar 18, 6:34 am, Martin DeMello <> wrote:
>> I'm new to Erlang, and having a bit of trouble coming up with the
>> right way to do this:
>> I have a set of mnesia triggers that watch for various db events. I
>> now want to have a persistent notification list that supports the
>> following two operations efficiently:
>> 1. insert a new event, with timestamp
>> 2. retrieve all events between two given timestamps
>> and possibly less efficiently
>> 3. compact the table (combine several updates to a single object into
>> a single row)
>> This posthttp://groups.google.com/group/erlang-programming/browse_thread/threa...
>> seems to imply that simply storing the notifications as an mnesia
>> table is a bad idea.
>> martin

More information about the erlang-questions mailing list