【问题标题】:Get or calculate Mnesia total size获取或计算 Mnesia 总大小
【发布时间】:2020-08-19 19:40:34
【问题描述】:

我想找到一个 mnesia 数据库的总大小。我只有一个节点。

我可以从某个函数中获取 mnesia 的大小还是可以通过某种方式计算它?

我查看了文档http://erlang.org/doc/man/mnesia.html,但找不到获取整个数据库的此类信息的函数。

我需要使用table_info/2 计算每个表吗?如果是的话怎么办?

注意:我不知道如何处理当前数据点,大小为 2(用于测试我只有 2 个条目),内存为 348。

【问题讨论】:

  • 数据库是用disc_copies 选项创建的吗?还是只有 RAM?
  • @AlekseiMatiushkin 我没有指定任何东西,因为我正在测试它。从我发现disc_copies 默认情况下没有设置。
  • memory 选项返回使用的字数,根据您的 CPU 架构,它是 32/64 位,因此字长为 4/8 字节。在你的情况下 348 * 4 或 * 8

标签: erlang elixir mnesia


【解决方案1】:

您需要使用mnesia:system_info(tables) 遍历所有表,并使用mnesia:table_info(Table, memory) 读取每个表内存以获取您的表占用的words 的数量。要将该值转换为字节,您可以首先使用erlang:system_info(wordsize) 获取您的机器架构的字大小(在 32 位系统上,字为 4 字节,64 位为 8 字节)并将其乘以您的 Mnesia表内存。一个粗略的实现:

%% Obtain the memory in of bytes of all the mnesia tables.
-spec get_mnesia_memory() -> MemInBytes :: number().
get_mnesia_memory() ->
  WordSize = erlang:system_info(wordsize),
  CollectMem = fun(Tbl, Acc) ->
   Mem = mnesia:table_info(Tbl, memory) * WordSize,
   Acc + Memory
  end,
  lists:foldl(CollectMem, 0, mnesia:system_info(tables)).

【讨论】:

  • 谢谢我最终也这样做了,方式完全相同:)
猜你喜欢
  • 2011-04-09
  • 2014-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-18
  • 2017-12-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多