Repository navigation
Description
Alexandre Navarro opened SPR-6252 and commented
Hi,
I will expose my problem.
I'm writing Swing applications and I like using Spring in my client (not very common in a Swing application) because it is useful when you call some Remote Services (RMI, WS) by using the different Spring Proxy Clients or if you want to seperate your Business logic and GUI logic and so easy to test your gui.
The problem using Spring in Swing application is when you're making a Swing application, you need to inject in your Controller/View (JPanel for instance) some beans Spring. But your JPanel is not instanciated by Spring (and you can't it).
To resolve this problem, I found 2 solutions
- create a kind of ServiceLocator (where the applicationContext is instanciated). When you want to inject a bean Spring, you must ServiceLocator.getInstance().getYourSpringBean(). It is very old-fashioned and has all problems related to static singleton (not easy too test, problem in Netbeans RCP like Tomcat for static stuffs ...).
- use
@Configurableon your panel (not instanciated by Spring) to inject with@Autowiredin some spring bean. It very clean and elegant on my point of view.
I made a small application with @Configurable and it works but it reveals some performance and memory usage problems.
When you use a GUI with a ServiceLocator, the startup of this application is something like 2 s (1s for Swing and 2s for spring context in lazy mode) and the memory usage is 10 mo.
When you use the same GUI with @Configurable (with the spring agent) the startup of the application is something like 10 s and the memory usage is 50-60 mo.
I attached a very small application example to show the problem. With this sample,
when you use a GUI with a ServiceLocator, the startup of this application is something like 900 ms (250 ms for Swing and 650 ms for spring context in lazy mode) and the memory usage is 1.2 mo.
When you use the same GUI with @Configurable (with the spring agent) the startup of the application is something like 3.6 s (1350 ms for Swing and 2280 ms for spring context in lazy mode) and the memory usage is 8 mo.
So the performance and memory usage is degraded by 5.
I tested with Spring 2.5.6 and with 3.0RC1 and the behaviour is the same.
Can you explain this behaviour? Is it normal? Maybe I have misconfigured my applicationContext. Can I specify the package where @Configurable classes are located to improve performance?
Honnestly, with these problems, @Configurable is just unuseable for production GUI application but only for unit tests.
Alexandre
Affects: 2.5.6, 3.0 RC1
Attachments:
- spring-configurable.zip (9.55 kB)
2 votes, 5 watchers
Activity
spring-projects-issues commentedon Oct 20, 2009
Alexandre Navarro commented
The sample.
spring-projects-issues commentedon Nov 12, 2009
Alexandre Navarro commented
I think it is possible to force with META-INF/aop.xml to load with the agent only some classes of a package (Adrian Coyler told me that last week during the "Rencontre Spring at Paris"), but I did not try it if it works better.
spring-projects-issues commentedon Nov 12, 2009
Ramnivas Laddad commented
This very much looks like a problem due to wide application of LTW. If you can add META-INF/aop.xml (anywhere in classpath) with content similar to the following, you should see substantial performance gains:
<aspectj>
<weaver>
<exclude within="com.yourcompany.app.ui..*"/> <!-- make sure your
@Configurableclasses are selected by this, and if possible very little else --></weaver>
</aspectj
spring-projects-issues commentedon Nov 12, 2009
Alexandre Navarro commented
I tried with
<aspectj>
<weaver>
<include within="fr..*"/> <!-- make sure your
@Configurableclasses are selected by this, and if possible very little else --></weaver>
</aspectj
The result on my PC is :
When you use a GUI with a ServiceLocator, the startup of this application is something like 900 ms (250 ms for Swing and 650 ms for spring context in lazy mode) and the memory usage is 1.2 mo.
When you use the same GUI with
@Configurable(with the spring agent) the startup of the application is something like 3.6 s (1350 ms for Swing and 2280 ms for spring context in lazy mode) and the memory usage is 8 mo.When you use the same GUI with
@Configurable(with the spring agent) with the aop.xml the startup of the application is something like 2.4 s (800 ms for Swing and 1500 ms for spring context in lazy mode) and the memory usage is 5.1 mo.To sum up,
Startup Time 900 ms 3600 ms 2400 ms
Memory 1.2 mo 5.1 mo 8.3 mo
The aop.xml improves the performance and memory usage but not a lot compared to the version without agent (notably the memory is very problematic)
spring-projects-issues commentedon Nov 12, 2009
Michael Isvy commented
Also, Ramnivas was talking about wide use of LTW. Alexandre, as far as I can remember, you did all your testing with some pretty small applications isn't it?
So I'm not sure it could be due to the fact that AspectJ parses too many classes (especialy for the high memory part).
spring-projects-issues commentedon Nov 12, 2009
Ramnivas Laddad commented
Michael, by "wide" I meant more classes are exposed to the weaver (whether or not they get woven due to pointcut expression).
Alexandre, can you tighten "fr..*" more? I assume that your Swing classes that carry
@Configurableare limited to very few packages. Note that you can use || expression or even multiple <include> elements. For example:<include within="fr.app.ui1..* || fr.app.ui2..*"/>
or
<include within="fr.app.ui1..*/>
<include within="fr.app.ui2..*/>
Also note that weave-time weaving should work the best in your scenario (is there a reason you cannot use it?).
spring-projects-issues commentedon Nov 12, 2009
Alexandre Navarro commented
I retried with
<aspectj>
<weaver>
<include within="fr.TestFrame"/> <!-- make sure your
@Configurableclasses are selected by this, and if possible very little else --></weaver>
</aspectj>
And I didn't have any improvement compared to <include within="fr..*"/> (I have a very few classes in fr in my sample).
To respond to Mickael, my sample is effectively a very small application. When I developped a bigger application, the problem becomes very problematic notably for the memory and the startup time (as I described in the description of the issue).
My last test seems to prove that the problem does not come from too many classes are exposed to the weaver.
spring-projects-issues commentedon Nov 12, 2009
Alexandre Navarro commented
I made a mistake on my table of performance (inversion of 2 results)
Startup Time 900 ms 3600 ms 2400 ms
Memory 1.2 mo 8.3 mo 5.1 mo
spring-projects-issues commentedon Aug 30, 2012
Thomas Pasch commented
Dear Alexandre,
perhaps you could turn on the debug log level for the spring stuff and check if the problem is similar to #14176.
spring-projects-issues commentedon Sep 22, 2015
Juergen Hoeller commented
Closing groups of outdated issues. Please reopen if still relevant.