Mostly read only using DETS

So, I use ETS - works great. However, I use it as a route data cache, which I load when the module loads, and save it when changes are made (it is read much more than it is written).

I thought DETS would make things a lot cleaner - I don’t have to worry about managing table storage. Would this be a good use of DETS? (size is not a problem, mainly regarding a significant increase in read performance - all data can easily fit into memory).

+4
source share
3 answers

In most cases, DETS is much slower than ETS, but I assume that if your data size is small, then most if it is cached with a disk cache and it will be faster to get the second time you read it, so the best thing is to try it with your type of use

But did you think you were using Mnesia instead of ETS directly? With disk copies like Mnesia, you get ETS speed and still persistence.

+4
source

Straight from Service Message Page :

"Since all operations performed with Dets are disk operations, it is important to understand that a single search operation includes a sequence of disk searches and reads. For this reason, Dets functions are much slower than the corresponding Ets functions, although Dets exports a similar interface . "

That is, for storage with reading basically Dets is not an optimal choice.

(I have to admit that I think this design decision is strange. The best implementation is to cache recent requests. However, since Ets and Dets are basic tools in Erlang, I believe that the developers left this optimization to users.)

+2
source

For recording rarely, read a lot of the data that you keep in order in memory, see "Mochiglobal". Mochiweb has a neat module that uses Erlang shared memory for constant modules through a code management system to provide ultra-quick access to terms by generating modules with setpoint values ​​in the form of constants on the fly.

Riak uses Mochiglobal for the state of the ring, IIRC.

Requests source:

https://github.com/mochi/mochiweb/blob/master/src/mochiglobal.erl

There is absolutely no perseverance here, but if you want to greatly optimize your reading, you cannot get much better than that.

0
source

Source: https://habr.com/ru/post/1336904/


All Articles