Erlang tool -- recon

时间:2022-06-01 13:04:52

遇见recon 以来, 每次定位系统瓶颈, 总是能让我眼前一亮. 比如说, 定位非尾递归导致的内存暴涨, 定位引发CPU满载的进程.得心应手,每每额手称庆.

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

CPU 统计相关

在ferd 大神放出的 Erlang_In_Anger 中提到了

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.

引用中提到的"this function" 是:

> recon:proc_window(reductions, , ).

也就是说, 将某个进程在一段时间内的reductions 变化大小作为这一段时间内该进程消耗CPU的程度.

Memory Leaks

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

解决的方式 ferd 也有一些建议:

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. 

第一种方案rabbitmq 其实是在使用的, 第二种基本上不太可能, 第三种应该在代码中多加注意, 第四种也就是尽可能使用Erlang VM 所倡导的short-lived 进程, 第五种也就是进程hibernate 方案同样在之前写的一篇blog中有提到 .

Memory Fragmentation

内存碎片和Erlang 虚拟机内存管理方式有很大的关系, 也就是内存泄露, 最明显的现象就是erlang:memory() 显示出来的内存使用量远远小于操作系统报告出来(如 top)的使用量.

总结

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

基友们有啥问题, 可以提出来, 大家一起交流.

Erlang tool -- recon的更多相关文章

  1. Erlang tool -- lager overload protection

    log 这个事, 说大不大说小又不小. 大点的, 可以用scribe flume 这样的系统去做, 小点的, 也就打印一个调试信息而已. 在Erlang 中, log 这事情确实比较伤, error_ ...

  2. Erlang库 -- 有意思的库汇总

    抄自这里 首先,库存在的目的大致可分为:1.提供便利2.尽可能解决一些痛点 首先,我们先明确一下Erlang编程语言的一些痛点(伪痛点):1,单进程问题Erlang虚拟机属于抢占式调度,抢占式调度有很 ...

  3. [Erlang33]使用recon从网页查看Erlang运行状态

    0.需求分析 Erlang最好的卖点之一就是提供了一个非常强大的shell来查看Node运行时的各种状态,可以进行各种各样的内部查看,在运行时调试和分析,热更新代码.   但是总有一些在生产环境下要慎 ...

  4. Erlang 虚拟机内的内存管理(Lukas Larsson演讲听写稿)

    Erlang核心开发者Lukas Larsson在2014年3月份Erlang Factory上的一个演讲详细介绍了Erlang内存体系的原理以及调优案例: http://www.erlang-fac ...

  5. [Erlang 0122] Erlang Resources 2014年1月~6月资讯合集

    虽然忙,有些事还是要抽时间做; Erlang Resources 小站 2014年1月~6月资讯合集,方便检索.      小站地址: http://site.douban.com/204209/   ...

  6. [Erlang 0114] Erlang Resources 小站 2013年7月~12月资讯合集

    Erlang Resources 小站 2013年7月~12月资讯合集,方便检索.     附 2013上半年盘点: Erlang Resources 小站 2013年1月~6月资讯合集    小站地 ...

  7. erlang mac os 10.9 卸载脚本

    #!/bin/bash if [ "$(id -u)" != "0" ]; then echo "Insufficient permissions. ...

  8. 使用recon/domains-hosts/baidu_site模块,枚举baidu网站的子域

    使用recon/domains-hosts/baidu_site模块,枚举baidu网站的子域 [实例3-1]使用recon/domains-hosts/baidu_site模块,枚举baidu网站的 ...

  9. erlang调试技术之etop

    etop是erlang进程信息查看工具,类似于UNIX的top. 一.配置参数 node The measured node. Value: atom() Mandatory setcookie Co ...

随机推荐

  1. 【JQ+锚标记实现点击页面回到顶部】

    前言:今天想写个页面常用到的[点击回到页面顶部或是首页的功能],生活和职场一样,总会有低谷的时候,这个时候咱也别怂.别怂.别怂,说三遍!那都不是事,工作没了,再找呗,就像我上周五,团队解散那天,我是笑 ...

  2. The Web server is configured to not list the contents of this directory.

    部署一个ASP.NET MVC网站至一个全新的服务器Windows Server 2008 R2, 数据为MS SQL Server 2014 64bit Expression版本. 运行时,它第一次 ...

  3. php出现“syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM”错误的一种情况,及解决方法

    PHP中的“syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM”错误,可能是因为美元符号$的误用,看下面一种情况 class Test{         s ...

  4. Linux中ifcfg-eth0配置参数解释

    Linux中设置IP地址经常使用到ifcfg-eth0这个文件.  vi /etc/sysconfig/network-scripts/ifcfg-eth0 附录文件中的内容: DEVICE=eth0 ...

  5. asp.net 实现对xml文件的 读取,添加,删除,修改

    用于修改站内xml文件 已知有一个XML文件(bookstore.xml)如下:<?xml version="1.0" encoding="gb2312" ...

  6. IE iframe 中 js 的 cookie 读写不到的解决办法

    1.看这里(改服务器配置) http://www.cr173.com/html/16696_1.html 2.使用object模拟iframe,不使用iframe框架 <html> &lt ...

  7. 用过滤器和装饰者设计模式(静态代理)解决getParameter乱码问题

    post的乱码问题比较好解决,这里主要是对get请求的乱码做处理 解决思路:增强request对象的getParameter方法,使之 getParameter  直接获取到的就是解决乱码后的数据 有 ...

  8. checkbox之checked的方法&lpar;attr和prop&rpar;区别

    1. $('#checkbox').click(function(){ if($('#checkbox').is(':checked')) { $(".sendmailhui"). ...

  9. AE&plus;SceneControl源代码共享

    近来的,博友发私信或邮件交换,第一次使用前SceneControl代做一点project股票,做的很粗糙.我们希望对大家有帮助,欢迎留言交流哈萨克斯坦. 除了主开.保存.数据加载.询价,几个功能主要是 ...

  10. ajax请求处理和views处理函数的优先级

    当采用ajax处理请求的时候,在views函数中使用 return render(request,'XXX.html',{'error':form.get_error()}) 返回渲染模板时,会优先处 ...