Spring AOP Memory Leak - Misconfiguration?
Asked Answered
S

0

6

I am investigating the memory leak for quite a while now and I can not figure it out.

Basically my application queries a rest service around 20 times per minute, creates POJOs from the result and updates a database. For the database updates I use advices (mostly) after the query process. (I use Spring's Resttemplate for the queries)

The facts I do know:

  • VM has max fixed heap size of 350 mb (-Xmx350m)
  • java version 1.8.0_121
  • java runtime env: build 1.8.0_121-b13
  • java hotspot vm 64 bit: build 25.121-b13, mixed mode
  • Spring Core, Beans & Aop version: 4.3.9 Release
  • AspectJ tools version: 1.5.4

My application contains 3 different aspects around different interfaces. Starting investigating the memory leak I disabled the aspects completely (just didn't import the xml) and everything worked out fine.

Each aspect's job is to write data collected by the proxied object into the database. Hibernate is used as a dao framework. To be sure the problem is not cause by Hibernate I replaced all DAOs with DummyDAOs which implement the same interface but do in fact nothing at all.

Profiling with VisualVM for 2 hours gave the following:

Memory consumption with dummy daos Memory consumption with dummy daos

Memory consumption with actual daos Memory consumption with actual daos

Clearly both versions are steadily increasing ram, so i drew the conclusion hibernate is not causing the memory leak.

I then checked if my own code would cause a memory leak anywhere, but as I only use spring singletons I can fairly safely reject this. VisualVM shows all my components have only one instance, model pojos are not growing either.

My aspects are fairly small, configured like this:

Worker Aspect

<bean id="aroundWorkerAspect" class="background.aspects.AroundWorkerAspect" >
    <property name="afterReturningStrategies" ref="afterReturningStrategies" />
    <property name="beforeStrategies" ref="beforeStrategies" />
    <property name="afterThrowingStrategies" ref="afterThrowingStrategies" />
</bean>

<aop:config>
    <aop:aspect ref="aroundWorkerAspect">
        <aop:pointcut id="aroundEachWorker" expression="execution(* common.worker.IWorker.executeJob(common.jobs.IJob)) and args(job)" /> 
        <aop:around pointcut-ref ="aroundEachWorker" method = "processJob" />
    </aop:aspect>
</aop:config>

Process Factory Aspect

<aop:aspectj-autoproxy/>

<bean id="afterProcessFactoryFillJobAspect" class="background.aspects.AfterProcessFactoryFillJobAspect" >
    <property name="startStopLogDAO" ref="startStopLogDAO" />
</bean>

<aop:config>
    <aop:aspect ref="afterProcessFactoryFillJobAspect">
        <aop:pointcut id="getProcessAsJobList" expression="execution(* common.IProcessFactory.*(..))" />
        <aop:after-returning returning="process" pointcut-ref ="getProcessAsJobList" method = "loadDataIntoEndJob" />
    </aop:aspect>
</aop:config>

Rest Template Aspect

<aop:aspectj-autoproxy/>

<bean id="afterRestTemplateUpdateMgmtSanity" class="background.aspects.AfterRestTemplateUpdateMgmtSanity" >
    <property name="mgmtAppSanityDAO" ref="mgmtAppSanityDAO" />
</bean>

<aop:config>
    <aop:aspect ref="afterRestTemplateUpdateMgmtSanity">
        <aop:pointcut id="restTemplateExchange" expression="execution(* org.springframework.web.client.RestOperations.exchange(..))" /> 
        <aop:after-returning returning="responseEntity" pointcut-ref ="restTemplateExchange" method = "updateMgmtAppSanity" />
    </aop:aspect>
</aop:config>

Profiling for 30 Minutes and taking a snapshot at the start and now gave the following difs:

Without Hibernate Without Hibernate

With Hibernate enter image description here

I assume the memory leak is rather created by misconfiguration than an actual bug.

Sherleysherline answered 7/8, 2017 at 11:13 Comment(1)
Hi, I'm having a similar issue, where you able to solve this problem?Preamplifier

© 2022 - 2024 — McMap. All rights reserved.