您的位置:首页 > 其它

Erlang如何查找内存消耗过高原因

2016-12-24 14:26 267 查看


 

 第一步:

查看进程数目是否正常? erlang:system_info(process_count). 进程数目合理

第二步:

查看节点的内存消耗在什么地方?

> erlang:memory(). 

[{total,2099813400},

 {processes,1985444264},

 {processes_used,1985276128},

 {system,114369136},

 {atom,4509545},

 {atom_used,4507777},

 {binary,22756952},

 {code,10486555},

 {ets,50948808}]

显示内存大部分消耗在进程上,由此确定是进程占用了大量内存

第三步:

查看哪些进程占用内存最高?

> spawn(fun() -> etop:start([{output, text}, {interval, 1}, {lines, 20}, {sort, memory}]) end).

(以输出text方式启动etop,其间隔为1秒,输出行数为20行,按照内存排序. 这里spawn一个新进程,目的是输出etop数据时不影响erlang shell 输入.)

etop输出有点乱,超过一定范围变成了**.

第四步:

查看占用内存最高的进程状态

> erlang:process_info(pid(0,12571,0)).           

[{current_function,{mod_player,send_msg,2}},

 {initial_call,{erlang,apply,2}},

 {status,waiting},

 {message_queue_len,0},

 {messages,[]},

 {links,[<0.12570.0>]},

 {dictionary,[]},

 {trap_exit,false},

 {error_handler,error_handler},

 {priority,normal},

 {group_leader,<0.46.0>},

 {total_heap_size,12538050},

 {heap_size,12538050},

 {stack_size,10122096},

 {reductions,3795950},

 {garbage_collection,[{min_bin_vheap_size,46368},

                      {min_heap_size,233},

                      {fullsweep_after,65535},

                      {minor_gcs,0}]},

 {suspending,[]}]

其中” {total_heap_size,12538050},” 表示占用内存为 12358050 words(32位系统word size为4,64位系统word size为8, 可以通过erlang:system_info(wordsize) 查看),在64位系统下将近100M, 太夸张了!  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  erlang