DETS 大多只读使用
所以我一直在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在大多数情况下,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
直接来自 Dets 手册页:
也就是说,对于以读为主的存储,Dets 并不是最佳选择。
(我必须承认,我发现这个设计决策很奇怪 - 更好的实现应该缓存最近的查找。但是,由于 Ets 和 Dets 是 Erlang 中的基本设施,我猜实现者将优化留给了用户。)
Straight from the Dets man page:
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.)
对于很少写入的情况,读取可以保存在内存中的许多数据,请查看“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.