[erlang-questions] Mnesia Reads and Writes

Genti Bogu <>
Mon Jul 23 00:53:30 CEST 2012

Hello everybody,
This is my first Erlang project and I was evaluating Mnesia's performance.
I wrote a simple erlang module for doing read and write tests to a disc_copies mnesia database.
So the data are stored in the disk but the database is loaded in memory.
 A write test consists of a number of records inserted per second in the Database, and a read test consists on a number of records that are read per second from the db. Each read or write operation is done inside a transaction. The read and write tests are performed separately.
Based on Mnesia's performance I define the appropriate load (number of reads/sec or number of writes/sec) that mnesia can handle.
Since transactional reads require only read locks (other reads can be done without requiring a lock), and transactional writes require write locks (exclusive access), I was expecting for mnesia to handle more load for read tests than for write tests. However, the supported load is the same in both the cases. Another observation of mine is the CPU usage, which is around 70% in the read tests (7 times higher than the write tests). Does anybody know why it can happen?
Since, I do the read tests separately from the write ones, and I have only one db node, I tried doing mnesia reads without using transactions at all. I got a read time that was more than 20 times faster than the time obtained when doing transactional reads. Why is it so huge the difference in performance in such a case? We have just read locks which allow simultaneous read requests to be performed in parallel without any exclusive lock.
How does the locking mechanism work for transactional reads and writes in Mnesia, and how are these operation handled?

I would be glad if somebody could help me understand some basic stuff about Mnesia IO operations.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120722/f458725c/attachment.html>

More information about the erlang-questions mailing list