erlang编程注意事项

。内存泄漏

内存泄漏原因主要是:

- 动态创建atom
- 在进程字典中存储较大数据结构
- behavior state data 无限的增长(存储一个增长的list/proplist)
- 在底层跨进程共享较大的二进制数据

解决办法:

-避免动态创建atom(使用list_to_existing_atom/1或binary_to_existing_atom/1)

-避免使用进程字典(如果确要使用的话,要确保清除不再使用的键值)

-避免增长behaviour state(使用像Riak一样的持久方案)

-避免使用较大的二进制数据

。如何调试

Actually, GCs happen very frequently in Erlang(you can manually GC by calling erlang:garbage_collect(Pid)), as soon as a process 
heap fills up. The heap size is increased if removing the garbage is
not sufficient to allocate the next term on the heap.

Among the things suggested so far, I'd also look at the process
dictionary. It will be part of the output from sys:get_status/1 or
process_info/1, but e.g.

erts_debug:flat_size(process_info(Pid, dictionary))

could be a way to monitor it.

Another useful technique is to use

erlang:system_monitor(MonitorPid, [{large_heap, Limit}])

and having the MonitorPid call process_info/1 on the process in
question, any time it receives a large_heap message.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值