# Erlang tool -- recon

recon 是ferd 大神 释出的一个 用于生产环境诊断Erlang 问题的一个工具, 不仅仅是对Erlang stdlib 接口的封装, 还有memory fragmentation 相关的函数.

## CPU 统计相关

The reduction count has a direct link to function calls in Erlang, and a high count is usually the synonym of a high amount of CPU usage.

What’s interesting with this function is to try it while a system is already rather busy, with a relatively short interval. Repeat it many times, and you should hopefully see a pattern emerge where the same processes (or the same kind of processes) tend to always come up on top.

Using the code locations and current functions being run, you should be able to identify what kind of code hogs all your schedulers.

1> recon:proc_window(reductions, 3, 500).

## Memory Leaks

memory leaks 主要是 refc binary, 这一点主要是和binary 的内存结构有关, 之前写的一篇blog  有提到这个.

Once you’ve established you’ve got a binary memory leak using recon:bin_leak(Max) , it should be simple enough to look at the top processes and see what they are and what kind of work they do.
Generally, refc binaries memory leaks can be solved in a few different ways, depending on the source:

• call garbage collection manually at given intervals (icky, but somewhat efficient);

• stop using binaries (often not desirable);

• use binary:copy/1-210 if keeping only a small fragment (usually less than 64 bytes) of a larger binary;

• move work that involves larger binaries to temporary one-off processes that will die when they’re done (a lesser form of manual GC!);

• or add hibernation calls when appropriate (possibly the cleanest solution for inactive processes).

The first two options are frankly not agreeable and should not be attempted before all else failed. The last three options are usually the best ones to be used.

## 总结

recon 是个实际操作性很强的工具, 没有实际的使用案例, 很难说得清楚它的妙用.

posted on 2015-04-01 21:35  _00  阅读(1269)  评论(1编辑  收藏