Will dets perform disk readings on lookup with ram_file option?

124 views Asked by At

An option ram_file is described in DETS Erlang docs

open_file(name, args)

{ram_file, boolean()} - Whether the table is to be kept in RAM. Keeping the table in RAM can sound like an anomaly, but can enhance the performance of applications that open a table, insert a set of objects, and then close the table. When the table is closed, its contents are written to the disk file. Defaults to false.

this will perform save on disk after insert or update

What if i'll use open - then lookup - then close?

1

There are 1 answers

1
Hauleth On BEST ANSWER

I haven't checked in the docs, but I assume that this mean that the VM will open the file and potentially mmap it, so it is constantly kept in the memory and it will be synchronised with the file on the disk, but I think that the change still can end in the cache, so it can be not immediately written to disk. If you want to be sure that all changes have been flushed to the disk then use dets:sync/1 call on the table to force data to be flushed which is explicitly stated in the docs:

This also applies to tables that have been opened with flag ram_file set to true. In this case, the contents of the RAM file are flushed to disk.

It will not open nor close file after each lookup, but it will keep it opened until dets:close/1 will not be called on the given table. Opening and closing table for each lookup on the other hand can be expensive, so it would make whole usage of DETS a little bit meaningless.