Spring MVC + GAE = slow startup

867 views
Skip to first unread message

Tomas

unread,
Apr 8, 2012, 4:16:02 AM4/8/12
to google-a...@googlegroups.com
Hi guys,

I've decided to convert my servlet/jdo based app engine app to spring mvc (the current app is starting to limit me on doing quick changes/improvements in the code and as I have quite good experience with spring on standard non cloud platforms I've decided to give it a go).

So I've put together project including:

- Spring + Spring MVC + Apache Velocity
- ehcache + spring-annotations for ehcache + own decorators/interceptors for appengine memcached
- objectify
- some other util classes ie jsoup, commons (util, baens, logging, codec), gdata

The lib directory contains ~42MB of jars (including appengine libraries which makes ~25MB)

After deploy, the app takes 50+ seconds to start (sometime the first request get killed after 60 seconds and another app is started) - I've read some articles about speeding up the spring on gae and decided to do another little test. I've created testing app containing only spring + spring mvc with one controller (no other beans, but had to keep the annotation scan enabled for mvc mapping - but disabled the component scan). The controller simply forwards to JSP file with text. Deployed and the page got displayed after 13 seconds.

I knew the Spring with all proxies and scanning is not optimal for GAE but I wasn't expecting this at all - it seems like the app have issues with simple loading the libraries as I can see how the memory of instance is growing by 1 MB per second. I've tried to:

1) merge jars into 3-4 bigger ones
2) disable annotations (just for the test as with new spring mvc its quite hard to do some better mapping only in xml)
3) lazy load some spring beans

And I can save like 5-10 secods from those 50+ seconds of my startup - is it really so bad for everyone or is there some magic setting?

Whats your normal startup time of your spring based app?

jon

unread,
Apr 9, 2012, 1:48:35 AM4/9/12
to Google App Engine
Our app is also Spring-based. We did some optimisation about a year
ago. Don't really remember how quickly we got our app to start. I
think it was in the ballpark of the 13s result you got. 50s is too
long.

Here's what we've done:
* combine our own classes into one JAR
* reduce dependencies as much as possible (exclude unnecessary JPA/JDO
dependencies if you're not using them)
* turn off Spring autoscan (we list Controllers explicitly, but we do
use annotations inside the Controllers)
* use static instead of dynamic JSP includes when possible
* turn on JSP precompilation
* there may be a few other things I'm forgetting

Tomas

unread,
Apr 9, 2012, 4:12:39 PM4/9/12
to google-a...@googlegroups.com
Hi, I've done all of those already and nothing helps.

As I said - the simplest MVC with just minimal spring libraries (excluding jpa/jdo app engine lib) with one JSP with only htm in it tak 13+ secs to startup.

I've spent two days trying to optimize everything (annotations support, scanning, repacking to bigger jars) but nothing helps.

1) what version of spring do you use (maybe the 3.1 is causing troubles)
2) how many other libraries did you have in your application

Thanks.

jon

unread,
Apr 10, 2012, 9:47:57 AM4/10/12
to Google App Engine
Just did one quick test, it takes about 24 s to spin up an instance. I
guess all this code we've written has added about 10 s of startup
time. So far it hasn't been a problem because we reserve instances.

Oh there's one other trick that we do. We map /_ah/warmup to a servlet
that exercises as much of our stack as possible.

We use Spring 3.0.x. Our lib folder shows 47 individual JARs
(including our own). Yikes!

Jordi P.S.

unread,
Jul 10, 2012, 8:13:01 AM7/10/12
to google-a...@googlegroups.com
Hello guys,

Tomas, I'm facing the same issues as you. I have Spring MVC with velocity and one single JSP and I get startup times from 50+ seconds.
I started applying the measures you guys propose and I don't get major reductions.

Have you fixed this issue already?

Jordi.

Rerngvit Yanggratoke

unread,
Jul 10, 2012, 8:19:44 AM7/10/12
to google-a...@googlegroups.com
I read it earlier somewhere that Spring MVC is kind of too heavy for GAE. The cold start time will be much lower if you use some other lightweight libraries. However, this means you could not take advantages of mature and advanced framework like Spring anyway.

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/wzMKMUqjlQgJ.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.



--
Best Regards,
Rerngvit Yanggratoke 

Rick Mangi

unread,
Jul 10, 2012, 4:02:17 PM7/10/12
to google-a...@googlegroups.com
FWIW I gave up on spring for that same reason. All of the reflection, scanning and parsing of XML or annotations is just not designed for an environment like appengine. It's meant for apps that start up once and stay up for a long time.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to google-appengine+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

Joakim

unread,
Jul 11, 2012, 7:46:37 AM7/11/12
to google-a...@googlegroups.com
Out of interest, which framework(s) are you using to replace Spring?

Rick Mangi

unread,
Jul 11, 2012, 3:02:13 PM7/11/12
to google-a...@googlegroups.com
None specifically. We're just not using spring. Spring's not really a framework as much as it is a set of tools and glue for building things (although I guess spring-mvc is a framework). Our app is built mostly on jersey, objectify and backbone.js

Mauricio Aristizabal

unread,
Jul 12, 2012, 2:22:34 AM7/12/12
to google-a...@googlegroups.com
As I replied here http://code.google.com/p/googleappengine/issues/detail?id=7833 , I had the same issue and it became moot once I specified 1 reserved instance and enabled warmup requests (then new instances are not sent requests until they are ready, whether that takes 5 seconds or 50).
Reply all
Reply to author
Forward
0 new messages