Reducing boot time for Jersey + Grizzly server

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Reducing boot time for Jersey + Grizzly server

Arnaud Bailly
Hello,
I am using Jersey in an embedded Grizzly server (v.1.9.18i). Here is my starting code which is pretty much copy and pasted from introductory examples:

server = new GrizzlyWebServer(servicePort);
    
    ServletAdapter jerseyAdapter = new ServletAdapter();
    jerseyAdapter.addInitParameter("com.sun.jersey.config.property.packages", "my.package");
    jerseyAdapter.setContextPath("/");
    jerseyAdapter.setServletInstance(new ServletContainer());

    server.addGrizzlyAdapter(jerseyAdapter, new String[] { "/" });

    server.start();
    this.setPort(server.getSelectorThread().getPort());

However, I find startup time to be quite long, as I think jersey is scanning the packages, loading the classes, instantiating everything,... I would like to reduce startup time, possibly by defining ex-ante without relying on packages scanning the resources that will be served. Ideally, I would even like to set explicitly whcih objects will serve which resources and inject necessary resources beforehand.

How can I do this with Jersey ?

Thanks in advance,
Arnaud

Reply | Threaded
Open this post in threaded view
|

Re: Reducing boot time for Jersey + Grizzly server

Oleksiy Stashok-2
Hi Arnaud,

how much time does it take to startup?
How much time it takes to startup just Grizzly container?


server = new GrizzlyWebServer(servicePort);

             ServletAdapter noContent = new ServletAdapter(new HttpServlet() {
                 @Override protected void service(HttpServletRequest req, HttpServletResponse resp) {
                     resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
                 }
             });

     server.addGrizzlyAdapter(noContent, new String[] { "/" });

     server.start();
     this.setPort(server.getSelectorThread().getPort());


So we can separate possible network and/or Jersey issues.

Thanks.
Alexey.


On 03/26/2011 05:54 AM, Arnaud Bailly wrote:

> Hello,
> I am using Jersey in an embedded Grizzly server (v.1.9.18i). Here is my
> starting code which is pretty much copy and pasted from introductory
> examples:
>
>
> server = new GrizzlyWebServer(servicePort);
>
>      ServletAdapter jerseyAdapter = new ServletAdapter();
>
> jerseyAdapter.addInitParameter("com.sun.jersey.config.property.packages",
> "my.package");
>      jerseyAdapter.setContextPath("/");
>      jerseyAdapter.setServletInstance(new ServletContainer());
>
>      server.addGrizzlyAdapter(jerseyAdapter, new String[] { "/" });
>
>      server.start();
>      this.setPort(server.getSelectorThread().getPort());
>
>
> However, I find startup time to be quite long, as I think jersey is scanning
> the packages, loading the classes, instantiating everything,... I would like
> to reduce startup time, possibly by defining ex-ante without relying on
> packages scanning the resources that will be served. Ideally, I would even
> like to set explicitly whcih objects will serve which resources and inject
> necessary resources beforehand.
>
> How can I do this with Jersey ?
>
> Thanks in advance,
> Arnaud
>
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Reducing-boot-time-for-Jersey-Grizzly-server-tp6210445p6210445.html
> Sent from the Jersey mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Reducing boot time for Jersey + Grizzly server

Arnaud Bailly
Hello Oleksiy,
Thanks for your answer. I must confess I did not measure precisely the boot time, this is just a human feeling. And the console logs seem to point to the class scanning mechanims of Jersey as the main "culprit" :-)

Anyway, I managed to find a simple solution: Use an Application object to pass to the servlet container, with all resources and providers created explicitly in the getSingletons() overriden method. I am not sure this is canonical but works pretty well and BTW solves a problem I had with maintaining singleton semantics through static variables, which I basically hate...

Regards,
Arnaud
Reply | Threaded
Open this post in threaded view
|

Re: Reducing boot time for Jersey + Grizzly server

japod
Hi Arnaud,

On 03/28/2011 07:51 PM, Arnaud Bailly wrote:
> Hello Oleksiy,
> Thanks for your answer. I must confess I did not measure precisely the boot
> time, this is just a human feeling. And the console logs seem to point to
> the class scanning mechanims of Jersey as the main "culprit" :-)
>
> Anyway, I managed to find a simple solution: Use an Application object to
> pass to the servlet container, with all resources and providers created
> explicitly in the getSingletons() overriden method. I am not sure this is
> canonical but works pretty well and BTW solves a problem I had with

in fact, using the Application subclass is the standard
way to configure the JAX-RS application.

~Jakub


> maintaining singleton semantics through static variables, which I basically
> hate...
>
> Regards,
> Arnaud
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Reducing-boot-time-for-Jersey-Grizzly-server-tp6210445p6217507.html
> Sent from the Jersey mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: Reducing boot time for Jersey + Grizzly server

Cowtowncoder
On Tue, Mar 29, 2011 at 4:20 PM, Jakub Podlesak
<[hidden email]> wrote:

> Hi Arnaud,
>
> On 03/28/2011 07:51 PM, Arnaud Bailly wrote:
>>
>> Hello Oleksiy,
>> Thanks for your answer. I must confess I did not measure precisely the
>> boot
>> time, this is just a human feeling. And the console logs seem to point to
>> the class scanning mechanims of Jersey as the main "culprit" :-)
>>
>> Anyway, I managed to find a simple solution: Use an Application object to
>> pass to the servlet container, with all resources and providers created
>> explicitly in the getSingletons() overriden method. I am not sure this is
>> canonical but works pretty well and BTW solves a problem I had with
>
> in fact, using the Application subclass is the standard
> way to configure the JAX-RS application.

+1 for that -- while automatic introspection may be convenient, it is
often bit risky (as well as slow).
So there is nothing wrong in being explicit during bootstrapping.

-+ Tatu +-
Reply | Threaded
Open this post in threaded view
|

Re: Reducing boot time for Jersey + Grizzly server

Arnaud Bailly
Hello,

I was wondering then how it came it took me a bit of time to figure out this is the "best practice" with Jersey. An thought it might be better to advocate it as early as possible in the documentation which, AFAI remember is mostly oriented towards automatic discovery. A detailed example of wiring an applilcation, with resources and providers, might be helpful to get a grasp of how best integrate Jersey.

Best regards,
Arnaud
Reply | Threaded
Open this post in threaded view
|

Re: Reducing boot time for Jersey + Grizzly server

Hugo Visser
Hi Arnaud,

I was wondering if you are also seeing a speed up in
WebApplicationImpl _initiate? I'm currently using GuiceContainer and I
am explicitly binding the resources in Guice module. Looking at the
code this appears to be the same as passing an Application object.

The large delay in my case appears to be the actual init of the
WebApplicationImpl which takes about 1,5 seconds for our app, running
on appengine. I've been digging through the code trying to find
something to optimize, but didn't get anywhere. It would be great if
the bootstrapping delay could be reduced. Any hints in that area would
be appreciated.

Hugo

On Fri, Apr 1, 2011 at 2:33 PM, Arnaud Bailly <[hidden email]> wrote:

> Hello,
>
> I was wondering then how it came it took me a bit of time to figure out this
> is the "best practice" with Jersey. An thought it might be better to
> advocate it as early as possible in the documentation which, AFAI remember
> is mostly oriented towards automatic discovery. A detailed example of wiring
> an applilcation, with resources and providers, might be helpful to get a
> grasp of how best integrate Jersey.
>
> Best regards,
> Arnaud
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Reducing-boot-time-for-Jersey-Grizzly-server-tp6210445p6230789.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Reducing boot time for Jersey + Grizzly server

Arnaud Bailly
Hi Hugo,
Interesting indeed. When I removed packages scanning, there was a large improvement but I am still quite surprised by the boot time of the Grizzly+Jersey. As I already said, I did not measure nor profile anything, but my human-based feeling is consistent with what you are observing. Obviously, this is no big deal when your application is supposed to boot-up once in a while, but this is not my use case: Our application goes on and off and is part of another larger system.

I will try next week to get some profiling metrics.

Best regards,
Arnaud

On Fri, Apr 1, 2011 at 6:21 PM, Hugo Visser [via Jersey] <[hidden email]> wrote:
Hi Arnaud,

I was wondering if you are also seeing a speed up in
WebApplicationImpl _initiate? I'm currently using GuiceContainer and I
am explicitly binding the resources in Guice module. Looking at the
code this appears to be the same as passing an Application object.

The large delay in my case appears to be the actual init of the
WebApplicationImpl which takes about 1,5 seconds for our app, running
on appengine. I've been digging through the code trying to find
something to optimize, but didn't get anywhere. It would be great if
the bootstrapping delay could be reduced. Any hints in that area would
be appreciated.

Hugo

On Fri, Apr 1, 2011 at 2:33 PM, Arnaud Bailly <[hidden email]> wrote:

> Hello,
>
> I was wondering then how it came it took me a bit of time to figure out this
> is the "best practice" with Jersey. An thought it might be better to
> advocate it as early as possible in the documentation which, AFAI remember
> is mostly oriented towards automatic discovery. A detailed example of wiring
> an applilcation, with resources and providers, might be helpful to get a
> grasp of how best integrate Jersey.
>
> Best regards,
> Arnaud
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Reducing-boot-time-for-Jersey-Grizzly-server-tp6210445p6230789.html

> Sent from the Jersey mailing list archive at Nabble.com.
>



If you reply to this email, your message will be added to the discussion below:
http://jersey.576304.n2.nabble.com/Reducing-boot-time-for-Jersey-Grizzly-server-tp6210445p6231698.html
To unsubscribe from Reducing boot time for Jersey + Grizzly server, click here.

Reply | Threaded
Open this post in threaded view
|

Re: Reducing boot time for Jersey + Grizzly server

Hugo Visser
Yes, on appengine it is likewise in that sense: depending on the
traffic a vm gets killed or added so bootstrap time matters. I dug
around yesterday but haven't found anything solid yet, although my
primary suspect is the creation of AbstractResources that use
reflection to get to the annotations etc.

On Fri, Apr 1, 2011 at 7:14 PM, Arnaud Bailly <[hidden email]> wrote:

> Hi Hugo,
> Interesting indeed. When I removed packages scanning, there was a large
> improvement but I am still quite surprised by the boot time of the
> Grizzly+Jersey. As I already said, I did not measure nor profile anything,
> but my human-based feeling is consistent with what you are observing.
> Obviously, this is no big deal when your application is supposed to boot-up
> once in a while, but this is not my use case: Our application goes on and
> off and is part of another larger system.
>
> I will try next week to get some profiling metrics.
>
> Best regards,
> Arnaud
>
> On Fri, Apr 1, 2011 at 6:21 PM, Hugo Visser [via Jersey] <[hidden email]>
> wrote:
>>
>> Hi Arnaud,
>>
>> I was wondering if you are also seeing a speed up in
>> WebApplicationImpl _initiate? I'm currently using GuiceContainer and I
>> am explicitly binding the resources in Guice module. Looking at the
>> code this appears to be the same as passing an Application object.
>>
>> The large delay in my case appears to be the actual init of the
>> WebApplicationImpl which takes about 1,5 seconds for our app, running
>> on appengine. I've been digging through the code trying to find
>> something to optimize, but didn't get anywhere. It would be great if
>> the bootstrapping delay could be reduced. Any hints in that area would
>> be appreciated.
>>
>> Hugo
>>
>> On Fri, Apr 1, 2011 at 2:33 PM, Arnaud Bailly <[hidden email]> wrote:
>> > Hello,
>> >
>> > I was wondering then how it came it took me a bit of time to figure out
>> > this
>> > is the "best practice" with Jersey. An thought it might be better to
>> > advocate it as early as possible in the documentation which, AFAI
>> > remember
>> > is mostly oriented towards automatic discovery. A detailed example of
>> > wiring
>> > an applilcation, with resources and providers, might be helpful to get a
>> > grasp of how best integrate Jersey.
>> >
>> > Best regards,
>> > Arnaud
>> >
>> > --
>> > View this message in context:
>> > http://jersey.576304.n2.nabble.com/Reducing-boot-time-for-Jersey-Grizzly-server-tp6210445p6230789.html
>> > Sent from the Jersey mailing list archive at Nabble.com.
>> >
>>
>>
>> ________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://jersey.576304.n2.nabble.com/Reducing-boot-time-for-Jersey-Grizzly-server-tp6210445p6231698.html
>
> ________________________________
> View this message in context: Re: Reducing boot time for Jersey + Grizzly
> server
> Sent from the Jersey mailing list archive at Nabble.com.
>