title: Achieving the best write performance on a (local) Mnesia instance in Elixir/Erlang
body: <p>Short and sweet; I'm building a new project which I <em>could</em> back with ETS, but I'd prefer to back with Mnesia - due to things like built-in transactions which may come in handy. I <strong>don't</strong> care about replication and scaling onto other nodes, which is why I assume Mnesia's performance has overhead on ETS.</p>
  
  <pre><code>zackehh:~/GitHub/my_project$ MIX_ENV=test mix bench
  Settings:
    duration:      1.0 s
  
  ## BasicBench
  [19:24:15] 1/4: retrieve key hit mnesia
  [19:24:23] 2/4: retrieve key hit
  [19:24:30] 3/4: insert new key mnesia
  [19:24:33] 4/4: insert new key
  
  Finished in 25.24 seconds
  
  ## BasicBench
  insert new key                 10000000   0.63 µs/op
  retrieve key hit               10000000   0.64 µs/op
  retrieve key hit mnesia        10000000   0.69 µs/op
  insert new key mnesia            500000   4.70 µs/op
  </code></pre>
  
  <p>I ran a few (local) benchmarks, and it's clear that Mnesia is comparable for read perf, but the write perf is far slower. I'd like to know if there are any ways to speed it up (e.g. turning off replication checking, etc).</p>
  
  <p>Additional info:</p>
  
  <p><strong>Mnesia Table:</strong></p>
  
  <pre><code>[
      { :ram_copies, [node()] },
      { :local_content, true },
      { :attributes, [:key,:value] }
  ]
  </code></pre>
  
  <p><strong>Tests</strong></p>
  
  <ul>
  <li>ETS operations use <code>:ets.lookup/2</code> and <code>:ets.insert/2</code></li>
  <li>Mnesia operations use <code>:mnesia.dirty_write/1</code> and <code>:mnesia.dirty_read/2</code></li>
  </ul>
  
  <p>I've been trawling the docs for hours and nothing has jumped out as a potential way to speed this up - so I might be staring into a perf wall, but if someone could clarify/confirm/suggest, it'd be appreciated.</p>