Was {ram_file, true} option to dets:open_file() once a good idea?

Scott Lystig Fritchie fritchie@REDACTED
Wed May 1 06:35:37 CEST 2002

Reading the docs for dets, I see this in the discussion of

    {ram_file, bool()}, whether the table is to be kept in RAM. Keeping
    the table in RAM may sound like an anomaly, but can enhance the
    performance of applications which 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. The default value is false.

However, when I use it to simply insert a bunch of tuples into a dets
table, the result is about twice as slow (if not even worse) as if I
omit it/set it to false.

Was this option a good idea once upon a time?  On my 500MHz Pentium
III laptop, adding 800,000 tuples with {ram_file, false} takes 3
minutes.  I aborted adding 500,000 tuples with {ram_file, true} after
7 min 30 seconds.  Perhaps it's a good option to use when the file
system is on a floppy disk or a *really* busy hard drive circa 1990?



% Timed via: time erl -run test dets {N} true|false -run erlang halt

-export([dets/1, dets/2]).

dets([S, RamFile]) ->		   % erl -run test dets N true|false
    dets(list_to_integer(S), list_to_atom(RamFile)).

dets(N, RamFile) ->
    io:format("dets starting inserting ~w objects\n", [N]),
    T = dets_test,
    {ok, T} = dets:open_file(T, [
				 {estimated_no_objects, N},
				 {ram_file, RamFile}
    dets_insert(T, N),
    ok = dets:close(T),
    io:format("dets done inserting ~w objects\n", [N]),
dets_insert(T, 0) ->
dets_insert(T, X) ->
    K = <<X:32>>,
    X2 = X * 2,
    V = <<X2:32>>,
    ok = dets:insert(T, [{K, V}]),
    dets_insert(T, X - 1).

More information about the erlang-questions mailing list