[erlang-questions] mnesia async vs sync

Roberto Ostinelli <>
Mon Mar 14 16:54:10 CET 2016


On Mon, Mar 14, 2016 at 4:27 PM, Dan Gudmundsson <> wrote:

> On Mon, Mar 14, 2016 at 1:54 PM Roberto Ostinelli <>
> wrote:
>
>> On Mon, Mar 14, 2016 at 12:47 PM, Dan Gudmundsson <>
>> wrote:
>>
>>> Try using mnesia:write instead of mnesia:dirty_write inside your fun.
>>>
>>
>> Making this change makes sync_dirty much slower when there are more than
>> just one node. So, this clarifies that probably using dirty_write with
>> sync_dirty falls back to async_dirty anyway.
>>
>
> dirty_write does not care if you use async_dirty, sync_dirty or apply fun
> directly.
>

Paraphrasing what I've said, so yes. :)


>
>
>> However, the findings still persist: the more nodes you add, the slower
>> the writing to mnesia is, even when using async_dirty.
>>
>>
> I don't see the problem with that, you run more code, and send more
> messages when you have more nodes.
> When running with one node, you only use the local node with no
> distribution at all, with several nodes you might block on send because
> tcp buffers are full and so on.
>

Sure, but that's not what is written in the docs. Here they are again:

"By passing the same "fun" as an argument to the function
mnesia:sync_dirty(Fun [, Args]), it is performed in almost the same context
as the function mnesia:async_dirty/1,2. The difference is that the
operations are performed synchronously. The caller waits for the updates to
be performed on all active replicas."


and

"The functions wait for the operation to be performed on one node but not
the others. If the table resides locally, no waiting occurs."




> You should use mnesia:write and compare async_ vs sync_.
>

Which is what I did in my previous email. :)
The findings are that async_dirty also has a significant performance loss.

Best,
r.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160314/0ed66324/attachment.html>


More information about the erlang-questions mailing list