erlang - dets 会在使用 ram_file 选项查找时执行磁盘读取吗?

标签 erlang elixir dets

DETS Erlang 文档中描述了一个选项 ram_file

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.

这将在插入或更新后在磁盘上执行保存

如果我会用呢 打开 - 然后查找 - 然后关闭?

最佳答案

我没有查看文档,但我假设这意味着 VM 将打开文件并可能mmap 它,所以它一直保存在内存,它会与磁盘上的文件同步,但我认为更改仍然可以在缓存中结束,因此不会立即写入磁盘。如果您想确保所有更改都已刷新到磁盘,请使用 dets:sync/1调用表以强制刷新数据,这在文档中有明确说明:

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.

它不会在每次查找后打开或关闭文件,但它会保持打开状态,直到 dets:close/1 不会在给定的表上调用。另一方面,为每次查找打开和关闭表可能代价高昂,因此这会使整个 DETS 的使用变得毫无意义。

关于erlang - dets 会在使用 ram_file 选项查找时执行磁盘读取吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59304443/

相关文章:

elixir - 在混合任务中使用 Ecto

erlang - 当数据不适合内存时,适合 Erlang 应用程序的数据存储后端

java - 将字符串数据从 Java/Erlang 发送到 Ada

erlang - 在 Erlang 中跟踪从邮箱中消费消息的行为

mysql - "Failed TCP accept: emfile"在 Ejabberd

windows - 在 Windows 7 机器上安装后 RabbitMQ 服务器没有启动

testing - Elixir - 在 doctest 中使用变量

erlang - erlang 的 `binary_to_term` 是否总是能够读取生成的二进制 `term_to_binary` 的任何先前版本?