Announcement Announcement Module
Collapse
No announcement yet.
Aspects scanning too many classes and method cache fills memory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Aspects scanning too many classes and method cache fills memory

    Hi Spring Comunity!

    I hope I can use some of your help in explaining the below situation.

    In our application we have several (actuall many, about 30) web services. Each web service resides in its own WAR file and has its own Spring context that is initialised when application starts.

    We also have a number of annotation-driven aspect classes that we apply to web service classes. In the begining the poincut expression looked like this:

    Code:
    @Pointcut("execution(public * my.package.service.business.*BusinessServiceImpl.*(..))")
      public void methodsToBeLogged() {
      }
    And AOP was enabled on services through <aop:aspectj-autoproxy /> entry in configuration.

    But when the number of web serivces grew, we began to experience OutOfMemoryExceptions on our servers. After doing some profiling and analysis it appeared that memory is taken by the cache that is kept by instances of AspectJExpressionPointcut class.

    Each instance's cache was about 5 MBs. And as we had 3 aspects and 30 services it resulted in 90 instances holding 450MBs of data in total.

    After examining the contents of the cache we realised that it contains Java reflection Method instances for all classes existing in the WAR even those which are not part of my.package.service.business package. After modifing the point cut expression to:

    Code:
    @Pointcut("execution(public * my.package.service.business.*BusinessServiceImpl.*(..)) && 
    within(my.package.service.business..*)")
      public void methodsToBeLogged() {
      }
    Memory usage was down to normal again. And all AspectJExpressionPointcut instances took less than 1MB all together.

    Can someone explain why is that? And why first point cut expression is not enough? Why the cache of AspectJExpressionPointcut is not shared?

    Best regards,
    superfilin

  • #2
    Issue is described in https://jira.springsource.org/browse/SPR-7678
    and also in http://stackoverflow.com/questions/4...144481#4144481

    Comment

    Working...
    X