配置内存泄漏策略
缺省情况下,WebSphere® Application Server 的泄漏检测策略处于关闭状态。可配置泄漏检测、预防和操作策略以适应您的应用程序和环境,以便在可能发生内存泄漏时生成报告和采取措施。泄漏检测、预防和主动修正为面对持续内存不足错误的服务器提供保护和弹性。如果检测到类装入器内存泄漏,那么 WebSphere® Application Server 会在日志中向您发送参考消息通知,并执行 JVM 堆转储以便您可诊断该问题。(可选)您也可以选择通过使用反射和其他方法以使 WebSphere Application Server 缓解和(如果可能)修正内存泄漏。
开始之前
类装入器内存泄漏是 Java™ 平台企业修订版 (Java EE) 应用程序中的一种常见错误。内存泄漏可能因细微应用程序错误或较复杂的用法(例如,第三方库)所导致。如果出现泄漏,那么说明使用了系统资源(例如,因为垃圾回收和 Java 堆而产生的 CPU 时间)。即使所有其他资源可用,系统也可能变得无法响应。除非内置了保护和预警系统,否则系统可能会保持此降级状态并因为内存不足错误而导致最终终止。
关于此任务
此服务的所有持久配置都是使用 JVM 定制属性完成的。没有管理控制台面板。在运行时,分别使用 MemoryLeakConfig mbean 和 MemoryLeakAdmin mbean 进行配置和管理;但是,在配置 JVM 定制属性前不会保存配置更改。
MemoryLeak 服务及其 mbean 仅在主管应用程序和服务请求的应用程序服务器中处于活动状态。此服务在 Deployment Manager、Node Agent、管理代理程序或其他服务器类型(例如,WebSphere 代理服务器等)上处于不活动状态。
过程
示例
可按此示例中所述使用 JVM 定制属性来配置和保存 WebSphere Application Server 的内存泄漏策略。可使用 MemoryLeakConfig MBean 在运行时更改内存泄漏检测、预防和策略配置。
可使用 MemoryLeakAdmin mbean 来执行内存泄漏策略的管理。泄漏策略会影响应用程序或服务器停止时应用程序服务器响应类装入器内存泄漏的方式。
# Scripting in JACL
# Get the object name of the MemoryLeak Configiration object you want to change the values on
set leakConfig [$AdminControl completeObjectName "type=MemoryLeakConfig,*"]
WebSphere:cell=smitaNode03Cell,name=LeakConfig,type=MemoryLeakConfig,node=smitaNode03,process=server1
# Get the object name of the MemoryLeak Administration object you want to issue operations
set leakAdmin [$AdminControl completeObjectName "type=MemoryLeakAdmin,*"]
WebSphere:cell=smitaNode03Cell,name=LeakAdmin,type=MemoryLeakAdmin,node=smitaNode03,process=server1
# Look at all the attributes of the MemoryLeakConfig mbean
wsadmin>$Help all $leakConfig
Name: WebSphere:cell=smitaNode03Cell,name=LeakConfig,type=MemoryLeakConfig,node=smitaNode03,process=server1
Description: Information on the management interface of the MBean
Class name: com.ibm.ws.runtime.component.MemoryLeakConfig
Attribute Type Access
JvmThreadGroupNames java.lang.String RW
FilterPrefixes java.lang.String RW
RenewThreadPoolNames java.lang.String RW
DetectAppCLLeaks boolean RW
ClearAppCLLeaks boolean RW
MonitorSystemApps boolean RW
NoDumps boolean RW
GenerateHeapDumps boolean RW
GenerateSystemDumps boolean RW
ClearReferencesStatic boolean RW
ClearReferencesInterruptThreads boolean RW
ClearReferencesStopTimerThreads boolean RW
ClearReferencesHttpClientKeepAliveThread boolean RW
ClearReferencesThreadLocal boolean RW
LeakSweeperDelay int RW
ThreadPoolRenewalDelayFactor int RW
PreventJreMemoryLeaks boolean RW
LeakConfiguration java.lang.String RO
Operation
Notifications
Constructors
# Print the current Memory Leak Policy configuration on the console
wsadmin>$AdminControl getAttribute $leakConfig LeakConfiguration
MemoryLeakConfig [getClass()=class com.ibm.ws.runtime.component.MemoryLeakConfig, hashCode()=37266644
preventJreMemoryLeaks true
detectAppCLLeaks true
monitorSystemApps false
leakSweeperDelay 10000
clearAppCLLeaks true
clearReferencesStopTimerThreads false
clearReferencesHttpClientKeepAliveThread true
clearReferencesInterruptThreads true
jvmThreadGroupNames [system, RMI Runtime]
clearReferencesStatic true
filterPrefixes [java., javax., com.ibm., org., sun., com.sun]
clearReferencesThreadLocal true
renewThreadPoolNames [WebContainer]
threadPoolRenewalDelayFactor 1
noDumps false
generateHeapDumps true
generateSystemDumps false
# Change the configuration
wsadmin>$AdminControl setAttribute $leakConfig ThreadPoolRenewalDelayFactor 10
wsadmin>$AdminControl setAttribute $leakConfig ClearReferencesStopTimerThreads true
# See the updated configuration
wsadmin>$AdminControl getAttribute $leakConfig LeakConfiguration
MemoryLeakConfig [getClass()=class com.ibm.ws.runtime.component.MemoryLeakConfig, hashCode()=37266644
preventJreMemoryLeaks true
detectAppCLLeaks true
monitorSystemApps false
leakSweeperDelay 10000
clearAppCLLeaks true
clearReferencesStopTimerThreads true
clearReferencesHttpClientKeepAliveThread true
clearReferencesInterruptThreads true
jvmThreadGroupNames [system, RMI Runtime]
clearReferencesStatic true
filterPrefixes [java., javax., com.ibm., org., sun., com.sun]
clearReferencesThreadLocal true
renewThreadPoolNames [WebContainer]
threadPoolRenewalDelayFactor 10
noDumps false
generateHeapDumps true
generateSystemDumps false
# Look at all the operations of the MemoryLeakAdmin mbean
wsadmin>$Help all $leakAdmin
Name: WebSphere:cell=smitaNode03Cell,name=LeakAdmin,type=MemoryLeakAdmin,node=smitaNode03,process=server1
Description: Information on the management interface of the MBean
Class name: com.ibm.ws.runtime.component.MemoryLeakAdmin
Operation
java.lang.String findLeaks()
java.lang.String fixLeaks()
java.lang.String fixLeaks(java.lang.String)
# Find current classloader memory leaks
wsadmin>$AdminControl invoke $leakAdmin findLeaks
CWMML0028I: The following web applications were stopped (reloaded, undeployed),
but their classes from previous runs are still loaded in memory,
thus causing a memory leak.[[78577.075.724.NWALogging#NWALoggingEJB.jar]].
# Fix ALL current classloader memory leaks
wsadmin>$AdminControl invoke $leakAdmin fixLeaks
CWMML0036I: Please watch the SystemOut log for results of the fix leak operation.
wsadmin>$AdminControl invoke $leakAdmin fixLeaks {"78577.075.724.NWALogging#NWALoggingEJB.jar"}
CWMML0036I: Please watch the SystemOut log for results of the fix leak operation.