如何获取Wildfly中当前正在使用的MDB实例数量?
Wildfly MDB 正在使用的实例数量监控问题
我在Wildfly中有多个MDB(消息驱动Bean)需要监控,希望获取每个MDB当前正在使用的Bean实例数量。
我目前使用以下命令从Wildfly获取MDB数据/统计信息:
/deployment=my-ear.ear/subdeployment=com.test.my-ejb.jar/subsystem=ejb3/message-driven-bean=*/:read-resource(include-runtime=true) --output-json
返回结果大致如下(仅展示一个MDB的结果):
{ "outcome": "success", "result": [ { "address": [ { "deployment": "my-ear.ear" }, { "subdeployment": "com.test.my-ejb.jar" }, { "subsystem": "ejb3" }, { "message-driven-bean": "MyMDB" } ], "outcome": "success", "result": { "activation-config": [ { "destinationLookup": "my_queue" }, { "acknowledgeMode": "Auto-acknowledge" }, { "destinationType": "jakarta.jms.Queue" }, { "maxSession": "3" } ], "component-class-name": "no.test.MyMDB", "declared-roles": [], "delivery-active": true, "execution-time": 0, "invocations": 0, "message-destination-link": null, "message-destination-type": null, "messaging-type": "jakarta.jms.MessageListener", "methods": {}, "peak-concurrent-invocations": 0, "pool-available-count": 5, "pool-create-count": 0, "pool-current-size": 0, "pool-max-size": 5, "pool-name": "my-pool", "pool-remove-count": 0, "run-as-role": null, "security-domain": "other", "timeout-method": null, "timers": [], "transaction-type": "CONTAINER", "wait-time": 0, "service": null }, "rolled-back": null } ] }
但结果中没有当前正在使用的Bean实例数量的信息。存在pool-current-size属性,但该属性似乎包含空闲Bean实例。
请问是否有方法从Wildfly获取正在使用的Bean实例数量,或者通过其他属性推算该数值?是否可以通过调整Bean实例空闲时间,结合pool-current-size来获取?
解决方案
1. 直接推算正在使用的实例数
你可以通过现有统计属性直接计算:
正在使用的实例数 = pool-current-size - pool-available-count
pool-current-size:连接池中当前存在的总实例数(空闲+正在使用)pool-available-count:当前处于空闲状态、可被分配的实例数
两者相减就能得到当前正在处理消息的MDB实例数量,这是Wildfly中最直接的计算方式。
2. 关于空闲时间调整的作用
调整Bean实例的空闲超时时间(通过pool子配置的idle-timeout-minutes等参数),只会影响空闲实例被回收的时机,不会改变pool-current-size和pool-available-count的统计逻辑。即使缩短空闲时间,也只是让空闲实例更快被销毁,pool-current-size会随之减少,但依然需要通过上述公式计算正在使用的实例数,无法直接通过pool-current-size得到目标值。
3. 额外监控维度补充
如果需要更细粒度的MDB运行数据,还可以关注以下属性:
peak-concurrent-invocations:历史最高并发调用数,用于评估MDB的负载峰值invocations:累计调用次数,结合时间维度可计算吞吐量execution-time:累计执行时间,可计算平均处理耗时
内容的提问来源于stack exchange,提问作者canEE
相关产品推荐
相关产品推荐

