Announcement Announcement Module
Collapse
No announcement yet.
Performance problems when using lots of AOP request scoped beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Performance problems when using lots of AOP request scoped beans

    I'm working on a semi-large application using Spring 3 and am running into performance problems when throwing hundreds of users at it at once. I'm using several request scoped beans using Spring's AOP proxy and I can see that every time I call any method on one of these beans, the CGLIB interceptor is invoked, which then calls AbstractBeanFactory.getBean(), which calls add() on a Synchronized Set of existing Spring beans. Since this add() is synchronized, it effectively locks up the server when there are thousands of calls to it all waiting to add to the same list.

    Is there a way to get around this using request scoped beans? I read in the Spring documentation that CGLIB isn't used if the bean implements any interface (http://static.springsource.org/sprin...p.html#d0e9015) but my request scoped beans all implement one (the same one in fact) and it's still happening. And I definitely need the beans to be request scoped because some of their fields are calculated in one part of the app for a particular request and then I use SpEL to get their value in a different part of the app during the same request. I think if I made the beans prototype scoped, I'd have a fresh object when I used SpEL to get them the second time.

    If it's not possible from stopping the CGLIB proxy's intercept() method from being called on every method call, is it possible to override AbstractBeanFactory.getBean() and hold a cache of registered beans? If so, where in the Spring config would I specify my custom bean factory?

    Here is a code sample that illustrates my problem. See the last two lines for comments describing where exactly I'm having issues.

    Code:
    <!-- Spring config -->
    <bean name="someBean" class="some.custom.class.SomeClass" scope="request">
        <property name="property1" value="value1"/>
        <property name="property2" value="value2"/>
        <aop:scoped-proxy/>
    </bean>
    
    <bean name="executingClass" class="some.other.custom.class.ExecutingClass" scope="singleton">
        <property name="myBean" ref="someBean" />
    </bean>
    
    
    public Interface SomeInterface {
        public String getProperty1();
        public void setProperty1(String property);
        public String getProperty2();
        public void setProperty2(String property);
    }
    
    public class SomeClass implements SomeInterface {
        private String property1;
        private String property2;
    
        public String getProperty1() { return propery1; }
        public void setProperty1(String property) { property1=property;}
    
        public String getProperty2() { return propery2; }
        public void setProperty2(String property) { property2=property;}
    }
    
    
    public class ExecutingClass {
        private SomeInterface myBean;
    
        public void execute() {
            String property = myBean.getProperty1(); // CGLIB interceptor is invoked here, registering myBean as a bean
            String otherProperty = myBean.getProperty2(); // CGLIB interceptor is invoked here too!  Seems like this is unnecessary. And it's killing my app.
        }
    }

    I asked this at StackOverflow and only got one answer, which I wasn't satisfied with. http://stackoverflow.com/questions/4771774/performance-problems-when-using-lots-of-aop-request-scoped-beans

  • #2
    You could try to switch to JDK interface proxies for your aop. If that doesn't speed up things, then use AspectJ ctw instead of Spring's proxy-based aop.

    Comment

    Working...
    X