监视Java应用程序的内存使用情况 [英] Monitoring own memory usage by Java application

查看:99
本文介绍了监视Java应用程序的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在一个Java进程中运行多个REST Web应用程序,以便在Akka的帮助下轻松保存内存和扩展。我想估计每个请求处理程序消耗多少内存并检测整个系统的这些内存。

I want to run several REST web applications inside one Java process to save memory and scale easily with help of Akka. I would like to estimate how much memory each request handler consume and detect these dangerous for the entire system.


  1. 是否可以在该进程内几乎实时监视内存使用情况,并找出每个请求处理程序使用了多少内存?我需要实现的目标是什么?是否有任何工具?

  1. Is it possible to monitor memory usage in almost real time inside that process and find out how much memory is used be each request handler? What I need to achieve that? Are there any tools?

是否可以捕获内存不足并基于内存使用情况做一些事情,例如崩溃请求处理程序超出假定的内存限制?如果是这样,可能会有什么不妥?

Is it possible to catch out of memory exception and based on memory usage do something, for example crash only request handlers exceeding assumed memory limit? If so, what could be bad with that?


推荐答案

回答你的问题第一个问题,有许多工具可用于监视内存使用情况,但我不知道在实际时间内将内存使用情况映射到线程的任何应用程序。在应用程序中,您可以使用 MemoryMXBean MemoryPoolMXBeans 监控内存使用情况,

To answer your first question, there are many tools which you can use to monitor memory usage, however i don't know of any application which maps memory usage to threads in "real" time. Within the application you can use the MemoryMXBean and MemoryPoolMXBeans to monitor memory usage,

回答你的第二个问题:不,不是真的。除了捕获OOME通常是一个坏主意之外,主要问题是接收异常的线程可能不是真正的罪魁祸首。 OOME被抛出进行最终分配请求的线程。但是,一些其他线程可能是填充大部分内存的线程。另一个问题是,由于OOME可能随时被抛出,因此可能会将其抛入应用程序中的某些关键代码中,使其处于残缺状态。长话短说,你几乎总是想要在收到OOME时重新启动你的应用程序。

To answer your second question: no, not really. Besides the fact that it is generally a bad idea to catch OOME, the primary problem is that the thread which receives the exception may not be the actual culprit. the OOME is thrown on the thread which makes the final allocation request. however, some other thread could be the one which filled up most of memory. The other problem is that since OOME can be thrown at any time, it could be thrown inside some critical code within your application, leaving it in a crippled state. long story short, you pretty much always want to restart your application when you receive an OOME.

这篇关于监视Java应用程序的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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