Tweak loading times of Jersey over AppEngine
Asked Answered
E

2

9

my application service is not able to start or respond to even warmup requests as the time taken by Jersey to scan the libraries is inordinate.

I have created application and hardcoded all the paths of the Resources for jersey.

<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.livily.rest.JerseyApplication</param-value>
</init-param>

Jersey Application has all the classes

public Set<Class<?>> getClasses()
{
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(com.livily.rest.visitor.UserRatingUtil.class);
}

However, jersey is scanning for lot of providers

Mar 8, 2013 3:39:40 PM com.sun.jersey.core.spi.component.ProviderServices getServiceClasses
CONFIG:     Provider found: class com.sun.jersey.server.impl.model.parameter.multivalued.StringReaderProviders$StringConstructor

It is doing it about 50-100 times and then

Mar 8, 2013 3:39:41 PM com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller createResource
FINEST: A new abstract resource created by IntrospectionModeler: AbstractResource("/current-status", - CurrentStatus: 1 constructors, 0 fields, 0 setter methods, 1 res methods, 0 subres methods, 0 subres locators )

for each one

The time taken in total is about 4-10 secs and appengine does not like this as it expects to wrap up the loading quickly; otherwise it starts giving weird 500 errors (for even static files).

I am stumped; any help will be appreciated.

Expostulation answered 8/3, 2013 at 15:52 Comment(6)
Not an answer, but I had similar load time issues with jersey and I moved to RestExpress (github.com/RestExpress/RestExpress), which doesn't have any of the J2EE weight.Disafforest
Cloudpre - that's not a valid commentDisafforest
Lipis - I moved to restexpress and to my surprise, it was actually slower in load time. I still get deadline exceptions. What is the best way to figure out what is taking lot of startup time? I changed logger level to all and find lot of output. Is this the best way?Expostulation
what other libraries are you using?Disafforest
appengine, apps-marketplace, appengine-api-labs, guava, jackson-mapper, resteasy, joda-time-1.6, jsoup, commons-lang, objectify (about 20 registrations), jackson-core, openid4java, gson, mustache-compiler, scannotation, jsr107cache, commons-logging, asm. Nothing unusual. I use 1.7.5 and jar all the classes under WEB-INF.Expostulation
Moving to F4 is one workaround for this mid-size app.Expostulation
V
1

I use the packages property to name which packages should be scanned as follows...

    <init-param>
         <param-name>com.sun.jersey.config.property.packages</param-name>
         <param-value>com.foo.myproviders</param-value>
    </init-param>
Valentia answered 17/3, 2013 at 17:48 Comment(2)
Jaytee - packages scanning are in fact slower than explicit defining the classes in the JaxRS Application.Expostulation
how can you explicit define the classes in JaxRS Application? I thought the package scanning was the only possibilityWrac
D
1

Set jersey.config.disableAutoDiscovery. See Configuration Properties for details.

<init-param>
    <param-name>jersey.config.disableAutoDiscovery</param-name>
    <param-value>true</param-value>
</init-param>
Dittmer answered 25/3, 2017 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.