【问题标题】:Size in MB of mnesia tablemnesia 表的大小(以 MB 为单位)
【发布时间】:2019-03-16 06:50:18
【问题描述】:

你怎么看:mnesia.info

例如,我只有一张表 some_table,:mnesia.info 将这个返回给我。

---> Processes holding locks <--- 
---> Processes waiting for locks <--- 
---> Participant transactions <--- 
---> Coordinator transactions <---
---> Uncertain transactions <--- 
---> Active tables <--- 
some_table: with 16020    records occupying 433455   words of mem
schema         : with 2        records occupying 536      words of mem
===> System info in version "4.15.5", debug level = none <===
opt_disc. Directory "/home/ubuntu/project/Mnesia.nonode@nohost" is NOT used.
use fallback at restart = false
running db nodes   = [nonode@nohost]
stopped db nodes   = [] 
master node tables = []
remote             = []
ram_copies         = ['some_table',schema]
disc_copies        = []
disc_only_copies   = []
[{nonode@nohost,ram_copies}] = [schema,'some_table']
488017 transactions committed, 0 aborted, 0 restarted, 0 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []

也叫:

:mnesia.table_info("some_table", :size)

它返回 16020,我认为这是键的数量,但我怎样才能获得内存使用情况?

【问题讨论】:

  • 根据the documentation,它是number of words,这意味着如果你在现代机器上,它是16_020 * 64 / 8 = 128_160字节≈128K
  • some_table: 16020条记录占用 433455 words of mem : 你要知道一个单词的大小你的机器(可能是 64 位,也可能是 32 位)
  • 这个词是不是让我很困惑,不知道怎么知道它的大小

标签: erlang elixir mnesia


【解决方案1】:

首先,您需要mnesia:table_info(Table, memory) 来获取您的表占用的words 的数量,在您的示例中,您获取的是表中的项目数,而不是内存。要将该值转换为 MB,您可以首先使用 erlang:system_info(wordsize) 来获取您的机器架构的字大小(在 32 位系统上,字为 4 字节,64 位为 8 字节),将其乘以您的 Mnesia 表内存以获取以字节为单位的大小,最后将值转换为兆字节,如:

MnesiaMemoryMB = (mnesia:table_info("some_table", memory) * erlang:system_info(wordsize)) / (1024*1024).

【讨论】:

  • 你能看看这个问题吗? stackoverflow.com/questions/52829549/mnesia-high-memory-usage 表大小和实际二进制内存使用量之间似乎存在很大差异(mnesia 存储字符串)
  • 我怀疑公式中缺少 *:MnesiaMemoryMB = (mnesia:table_info("some_table", memory) * erlang:system_info(wordsize)) / (1024*1024)。
  • 请小心。如果您的表使用disc_only_copiesmnesia:table_info 返回磁盘上存储的字节数,因此您不需要获取wordsize
【解决方案2】:

您可以使用erlang:system_info(wordsize) 来获取以字节为单位的字大小,在 32 位系统上,字是 32 位或 4 字节,在 64 位上是 8 字节。所以你的表使用的是 433455 x wordsize。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-06-12
  • 2020-09-30
  • 2013-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-17
相关资源
最近更新 更多