DETS 大多只读使用

发布于 2024-10-14 16:58:25 字数 185 浏览 9 评论 0原文

所以我一直在使用 ETS - 效果很好。但是,我将它用作路由数据的缓存 - 在模块加载时加载,并在进行更改时保存(读取的次数远远多于写入的次数)。

我认为 DETS 会让事情变得更加干净 - 我不必担心管理表的持久性。这是 DETS 的一个很好的用途吗? (大小不是问题,主要关心的是读取性能的大幅提高 - 所有数据都可以轻松放入内存中)。

So I have been using ETS - works great. However, I use it as a cache of route data - which I load when the module loads, and save when a change is made (it is read far more than written).

I was thinking that DETS would make things much cleaner - I don't have to worry about managing the persistence of the table. Would this be a good use of DETS? (size isn't an issue, mostly concerned about major increase in read performance - all the data can easily fit in memory).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与酒说心事 2024-10-21 16:58:25

在大多数情况下,DETS 比 ETS 慢得多,但我猜想,如果您的数据量很小,那么大多数情况下,它会被磁盘缓存缓存,并且在您第二次读取它时检索速度会更快,所以最好的事情是尝试一下您的使用类型

但是您是否考虑过直接使用 Mnesia 而不是 ETS?使用 Mnesia 表类型 Disc_copies,您将获得 ETS 的速度和持久性

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

But have you considered using Mnesia instead of ETS directly? With the Mnesia table type disc_copies you will get the speed of ETS and still persistency

锦爱 2024-10-21 16:58:25

直接来自 Dets 手册页

“由于 Dets 执行的所有操作都是磁盘操作,因此重要的是要认识到单个查找操作涉及一系列磁盘查找和读取操作。因此,Dets 函数比相应的 Ets 慢得多函数,尽管 Dets 导出类似的接口。”

也就是说,对于以读为主的存储,Dets 并不是最佳选择。

(我必须承认,我发现这个设计决策很奇怪 - 更好的实现应该缓存最近的查找。但是,由于 Ets 和 Dets 是 Erlang 中的基本设施,我猜实现者将优化留给了用户。)

Straight from the Dets man page:

"Since all operations performed by Dets are disk operations, it is important to realize that a single look-up operation involves a series of disk seek and read operations. For this reason, the Dets functions are much slower than the corresponding Ets functions, although Dets exports a similar interface."

That is, for a read-mostly storage, Dets is not an optimal choice.

(I must admit I find this design decision weird - A better implementation should cache recent lookups. However, since that Ets and Dets are basic facilities in Erlang, I guess that the implementors left that optimization for the users.)

标点 2024-10-21 16:58:25

对于很少写入的情况,读取可以保存在内存中的许多数据,请查看“Mochiglobal”。 Mochiweb 有一个简洁的模块,它通过代码管理系统滥用 Erlang 的模块常量共享堆,通过动态生成具有给定值作为常量的模块来提供对术语的超快速访问。

Riak 使用 Mochiglobal 作为环态 IIRC。

她的来源:

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

当然,这里绝对没有持久性,但如果您希望大力优化读取,那么没有比这更好的了。

For write rarely, read many data that you're okay keeping in memory, check out a 'Mochiglobal'. Mochiweb has a neat module that abuses Erlang's shared heap for module constants via the code management system to provide super-fast access to terms by generating modules with given values as constants on the fly.

Riak uses a Mochiglobal for the ring state, IIRC.

Hers's the source:

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

There's absolutely no persistence here, of course, but if you're looking to heavily optimize reads, you can't get much better than this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文