简体   繁体   English

使用ets函数读取mnesia表(erlang)

[英]Using ets function to read mnesia table (erlang)

working on an erlang project using mnesia (some tables ram copies, some tables disk copies, some tables both). 使用mnesia处理一个erlang项目(一些表是ram副本,一些表是磁盘副本,某些表两者都)。 in an attempt to optimize a certain read (ram table), i used the ets lookup rather than the mnesia dirty_read i had been using, and timed both versions of the routine. 为了优化某个读取(内存表),我使用了ets查找而不是我一直在使用的mnesiadirty_read,并为例程的两个版本计时。 the ets lookup was significantly faster than the mnesia dirty_read. ets查找的速度明显快于mnesia的dirty_read。

my question is whether there is some 'gotcha' or 'catch' to reading an mnesia table using ets vs mnesia (there must be, otherwise there is no reason for the slower mnesia read to exist). 我的问题是使用ets vs mnesia读取某张记忆表是否有一些“陷阱”或“捕捉”(必须存在,否则就没有理由存在读取速度较慢的记忆)。 if it makes any difference, i don't need and am not using any "distrubuted" or "nodes." 如果有什么不同,我不需要,也没有使用任何“扭曲的”或“节点”。 in other words, i am and will only be using a single node on a single computer. 换句话说,我现在将仅在单台计算机上使用单个节点。

mnesia:dirty_read does a rpc call even if the table is local. 即使表是本地的,mnesia:dirty_read也会执行rpc调用。 Also it checks for the current activity context and maintains it even for dirty lookups. 此外,它还会检查当前的活动上下文并维护它,甚至进行脏查找。 This will result in the extra time required for the lookup. 这将导致查找所需的额外时间。

In your case (where there is only one node with local mnesia), direct ets lookup should work but not recommended as it will be implementation dependent. 在您的情况下(只有一个带有局部记忆的节点),直接ets查找应该可以工作,但不建议这样做,因为它将依赖于实现。 The better would be to use mnesia:ets(Fun,[, Args]) . 最好使用mnesia:ets(Fun,[,Args])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM