简体   繁体   English

测量分布式应用程序的内存使用量

[英]Measure memory usage of a distributed application

What is the best way to measure memory usage of a distributed application? 测量分布式应用程序的内存使用情况的最佳方法是什么?

I'm not sure if using ps on each machine is the best approach on this problem -- the saner the solution, the better (: 我不确定在每台机器上使用ps是否是解决此问题的最佳方法 - 解决方案越精细,越好(:

PS: The application is in c++ , and is to be executed using linux . PS:应用程序是用c++ ,用linux执行。

Install one of several really good open source enterprise datacenter monitoring tools. 安装几个非常好的开源企业数据中心监控工具之一。 Good ones are: 好的是:

These are terribly easy to install and give you not only memory but also any other system property you could shake a stick at. 这些非常容易安装,不仅可以为您提供内存,还可以为您提供任何其他系统属性。

To get memory usage programmatically, read from /proc/self/statm : 要以编程方式获取内存使用情况,请从/proc/self/statm

#include <fstream>
#include <iostream>

int main()
{
        std::ifstream statm("/proc/self/statm");
        size_t mem_virt, mem_rss, mem_shared;
        statm >> mem_virt >> mem_rss >> mem_shared;
        std::cout << "Memory stats:" << std::endl <<
                     "Virtual memory size:  " << mem_virt   << std::endl <<
                     "Resident memory size: " << mem_rss    << std::endl <<
                     "Shared memory size:   " << mem_shared << std::endl;
        return 0;
}

I guess you mostly interested in resident memory size , that is, how much RAM is accessible to the program right now. 我猜你最感兴趣的是驻留内存大小 ,也就是说,程序现在可以访问多少RAM。 See an answer from ServerFault which describes the meaning of these three types. 请参阅ServerFault的答案,其中描述了这三种类型的含义。

I would suggest to implement simple logic in separate thread of your application. 我建议在应用程序的单独线程中实现简单的逻辑。 That will sleep most of time, wake up once in couple of minutes, call mallinfo and put that data to log or network. 这将在大部分时间内休眠,在几分钟内唤醒一次,调用mallinfo并将该数据放入日志或网络。

There's a memory checker app called alleyoop (which uses the valgrind lib) that can monitor a program. 有一个名为alleyoop的内存检查器应用程序(使用valgrind lib)可以监视程序。 I recommend checking this out: http://alleyoop.sourceforge.net/ 我建议检查一下: http//alleyoop.sourceforge.net/

You can use 您可以使用

cat /proc/PROC_PID/smaps 

in order to get the detail of all the memory pages used by your process. 以获取进程使用的所有内存页面的详细信息。 However, you don't have the indication whether the memory is really used or just reserved. 但是,您没有指示内存是真正使用还是仅保留。 There is also 还有

pmap -x PROC_ID, doing similar work.

Finally, there is 最后,还有

cat/proc/PROC_ID/status | grep Vm 

giving you informations about all memory types used by your program. 为您提供有关程序使用的所有内存类型的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM