开发者

How to improve Spring MVC performance?

Are there best practises how to improve the performance of spring webapps?

I use ehcache for static content, try to load JavaScript at the end of my app but the app doesn't run smooth yet. For a simple registration only the GET-request to map the u开发者_如何学JAVArl and initalize session and bean lastet over 7 sec.

Sure you can optimize a lot for specific, but I'd like to know about generell performance issues and how to handle those.

Patterns, best practises and so on are very wellcome here.


In general, I recommend:

  • build a test environment where you can execute the application and get at the inside
  • Write repeatable performance testing scripts, focusing both on absolute performance (e.g. "how long does it take to render this page") and performance at scale (e.g. "how does performance degrade under load?")
  • glue a profiler into your test environment. It's been a while since I worked on Java apps, but there are lots of them available.
  • run performance test whilst running your profiler. Work out what the bottleneck is. Fix the bottleneck. Rinse. Repeat.

I generally recommend NOT to have the test rig be similarly specified to production, because it makes it very hard to create enough load to stress the system. It's also very expensive.

If you have a "production-like" environment to test on, do it now - ideally, you'll get similar results as on the test environment, but not always; if at all possible, install the profiler and see where the bottleneck is.

Once you've done that, you can deploy the optimized app to your production environment.


Create performance-tests (like with jmeter). Profile your application, either with a full-blown profiler or by instrumentation. If you are using spring (and spring-configured datasources), I like javamelody a lot which is a simple plug-in that instruments and compiles performance-statistics of your application.

Run the test, check the profiling information, identify bottlenecks, optimize the worst offenders. Repeat until satisfied.

There is no inherent performance problem with Spring MVC. Performance issues comes from other areas. Bad SQL queries, slow external integrations, excessive JSTL crazyness in your views etc etc.


VisualVM is very useful for analyzing. Can be downloaded from link. Memory Pools and Visual GC plugins which are not installed by default, also useful to monitor memory usage and GC activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜