Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which is more efficent among ets and mnesia

ets:select vs mnesia:select Which is better to use.And also in case of insertion and deletion which one of these two we should use.I am working on ejabberd.Any pointers?

like image 681
Geek Avatar asked Feb 13 '15 06:02

Geek


1 Answers

tl;dr

They are tools built for different purposes: ETS is a fast K/V store, Mnesia is a database built atop them. Use the tool that fits your use case.

Discussion

Mnesia is built on top of ETS/DETS. Which is more efficient comes down to what features you are looking for. If you have simple tables with no additional logic, a single simple key to index and will only ever use the table purely in memory or from disk, then there is no difference between ETS and Mnesia and you won't be using any Mnesia features.

If, on the other hand, you need more than one index over the data, want to implement some caching behavior, need on-disk persistence but cached index performance, and other things you would expect from a database system, then you will either have to implement Mnesia-type features yourself on top of ETS/DETS or simply use Mnesia.

Very often I start with a few ETS tables when prototyping (or even on early versions of features in production), then start finding places I need data serialized and on disk, then realize I need multiple indexes, etc. and wind up moving a lot of the data management stuff that was initially in ETS into Mnesia anyway. If you abstract away the concept of data access properly it is not an issue to change the implementation of this part of your system either way. If you have select calls scattered throughout your modules, though, then you probably have other architectural issues to sort out that are much more important than ETS vs Mnesia.


Regardless what you use, make sure you are not doing something like creating a system-wide bottleneck in the form of a central repository of all state for the entire system. This is a mistake I see a lot of folks coming from a (C/Python/$imperative_lang + Postgres/MariaDB/$rbdms) sort of background make.

Read paragraphs 2-6 of ErlMUD Commentary: Architecture, Locations for an architectural discussion of state representation at a highish level.

like image 153
zxq9 Avatar answered Nov 10 '22 23:11

zxq9