用tomcat中的所有httpsess在任意时间点测量记忆消耗
我想测量Web应用程序中 httpsession
使用的内存百分比。
有什么方法可以在任意时间点运行的tomcat实例中使用所有 httpsession
s测量内存消耗,而无需修改应用程序?
我在tomcat中尝试的是
- ,
httpsession
的具体类是org.apache.catalina.session.session.standardsessession
。我已经使用VisualVM介绍了该应用程序,并指定org.apache.catalina.session.session.standardsession
in[Profiler] - [Memory Settings]
。但是它仅显示标准
本身的大小(contrenthashmap
的大小不包括标准
中包含的大小)。 - 我已经用飞行记录员介绍了该应用程序,并通过任务控制查看了结果。但是我找不到从
httpsession
引用哪些对象。 - 您可以使用
org.apache.catalina.catalina.session.session.managerbase.managerbase#findsessions()代码>并用Byteman和
sizeof.deepsizeof()
测量
httpsession
s的大小。但是,仅当创建新的httpsession
时,此BYTEMAN规则才能运行。我希望在任意时间点(例如每30秒内)使用httpsession
s测量内存消耗。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据@LMC的评论,我做了一个示例项目,以使用JMX获得httpsession的大小:
请注意,因为您无法访问
org.apache.catalina.session.session.managerbase
,因此此项目使用 byteman 。将ManagerBase
将对象存储到MBEANsessionmonitor
的静态字段中,并使用Byteman类似:并在JMX接口中使用它,例如:
According to the comment from @LMC, I made a sample project to get the size of HttpSession with JMX: https://github.com/satob/SessionSize
Note that because you cannot access
org.apache.catalina.session.ManagerBase
directly, this project uses ByteMan. Store theManagerBase
object to a static field of the MBeanSessionMonitor
with Byteman like:and use it in the JMX interface like: