在内存使用方面如何描述Erlang程序? [英] How to profile an Erlang program in terms of memory usage?

查看:110
本文介绍了在内存使用方面如何描述Erlang程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想进一步提高现有Erlang计划的效率。首先我想确定瓶颈,然后决定在哪里进一步优化。

我尝试过 fprof ,但它只提供有关总计和平均运行时间的信息。我最希望看到类似于fprof的输出的日志,但是关于函数和过程的平均和总内存使用情况。

I have tryed fprof, but it only gives information on total and average runtime. I would most like to see a log similar to the output of fprof, but in terms of average and total memory usage with respect to functions and processes.

对于初学者来说,配置一个不会生成过程的单个模块是足够的,只有它的函数才被调用。这将有助于我将程序分成不同的模块进行测试。

For starters it would be enough to profile a single module, that does not spawn processes, only it's functions would be called. This would already help, for I could separate the program to distinct modules for testing.

典型的可疑点是,列表正在处理中。

Typical suspicious points are, where bigger lists are being handled.

这里使用 ++ 已经通过列表解析:反向([Head | Tail])类似语法

Here the usage of ++ has been resolved by lists:reverse([Head|Tail]) like syntax.

我也考虑使用ETS表而不是List

I am also considering using ETS tables instead of Lists for cases with more than a few hundred elements.

提前谢谢!

推荐答案

一些广告为了我自己的缘故:一段时间我写了一个erlang gen_server,记录和记录系统统计信息,结合一些perl脚本解析它们并输出漂亮的图表。

Doing some advertising for my own sake: I wrote a little erlang gen_server a while ago, that records and logs system statistics, combined with a little perl script that parses them and outputs pretty charts.

我发现在加载下进行内存监视等功能非常有用,因为它允许您持续监视内存使用的详细视图,例如测试不同的内容。

I've found it pretty useful for doing memory watching etc. under load, as it allows you to continuously monitor a detailed view of the memory usage, while for instance testing different things.

erlang部分是公平的非侵入式,一个简单的gen_server,你可以从任何地方开始,你可以把它放在你的监督树下。您可以配置轮询频率等,并以简单的json格式将统计信息写入文件。

The erlang part is fairly non-intrusive, a simple gen_server that you can start from anywhere, you can just put it under your supervision tree. You can configure the poll frequency etc, and it will write statistics to a file in a simple json format.

然后Perl脚本运行,并将日志聚合到绘制图表。有基类,如果你知道一点perl,你可以轻松地编写一个类来记录和绘制你想要的任何自定义参数。

The perl script then runs over it, and aggregates the logs to draw charts. There are base-classes, and if you know a little perl, you can easily write a class to log and chart any custom parameter you want.

可以获取脚本来自: https://github.com/Amadiro/erlang-statistics

样本图表(Erlang节点泄漏原子):样品图表http://monoc.mo.funpic.de/ram-usage-vs-time.png

Sample chart (Erlang node that leaks atoms): Sample Chart http://monoc.mo.funpic.de/ram-usage-vs-time.png

希望这可以帮助你:)

Hope this helps you :)

这篇关于在内存使用方面如何描述Erlang程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆