You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martin_S <ma...@gmail.com> on 2007/09/13 20:39:44 UTC

How to init T5 pages on deployment? - 1st few hits would be faster

Tapestry 5 currently is slow when a user hits a page for the first time.
Does anyone know how to make T5 create all page instances at deploy time in
Tomcat? For example, the Hibernate project suggests using a
ServletContextListener to create a SessionFactory. Something similar would
be great in T5 to get a better response time when the first user hits a
page.
I know just doing requests from a utility class would be a quick-and-dirty
workaround, but surely there has to be a better way.
-- 
View this message in context: http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12660957
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Nick Westgate <ni...@key-planning.co.jp>.
ApplicationInitializer is a pipeline service:
http://tapestry.apache.org/tapestry5/tapestry-ioc/pipeline.html

Howard is saying you could contribute to ApplicationInitializer
in your AppModule to do what you want.

To find out about the "cleanup", use the source. Search for other
code that uses pages.

Cheers,
Nick.


Martin_S wrote:
> Hi Howard, I have found both ApplicationInitializer and ComponentSource only
> available by injection within a page which is already instantiated. What I
> was looking for is a way to create all pages (or even just one) before a
> user request would hit.
> 
> Also, could you give just a little bit more detail about what you mean with
> "perform a little bit of cleanup work"? What will it take for Tapestry to
> make pages return to the pool and stay available until undeploy time? This
> would also enable us to create a number of page objects per page and have
> them pooled and ready for hits. Especially if a minimum of them aren't
> garbage collected later.
> 
> For now, I would be more than happy with a semi-proper workaround. If write
> something decent, I'll try to contribute it somewhere. 
> 
> 
> Angelo Chen wrote:
>> Hi Howard,
>>
>> The deplay happens before I refer to _userExists, just displaying the page
>> takes a long time, you can see from the code below,  the _user field is
>> referred to in onSuccess which is after the page display: 
>>
>> @ApplicationState
>>     private SessionData _user;
>>
>>     private boolean _userExists;
>>
>>     String onSuccess() {
>>   
>>    }
>>
>>
>> Howard Lewis Ship wrote:
>>> You can inject the ComponentSource into an ApplicationInitializer and
>>> obtain
>>> the page by name.  There's some other cleanup I can't research now.
>>>
>>> It would be interesting to know exactly what is taking so long ... I
>>> think
>>> you may find it isn't until you reference your _user field that there's a
>>> delay, partly to set up the many necessary services, but also to create
>>> the
>>> HttpSession, which can be time consuming in some servers.
>>>
>>> On 9/13/07, Angelo Chen  wrote:
>>>>
>>>> Hi Howard,
>>>>
>>>> I'm quite ok with T5's speed when comes to page display first time, but
>>>> it
>>>> is really slow when a page contains :  @ApplicationState private
>>>> SessionData
>>>> _user; loaded first time. Is there a simple way to pre-load that page? 
>>>> I
>>>> know the page name, dont have to be generic.
>>>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Martin_S <ma...@gmail.com>.
Hi Howard, I have found both ApplicationInitializer and ComponentSource only
available by injection within a page which is already instantiated. What I
was looking for is a way to create all pages (or even just one) before a
user request would hit.

Also, could you give just a little bit more detail about what you mean with
"perform a little bit of cleanup work"? What will it take for Tapestry to
make pages return to the pool and stay available until undeploy time? This
would also enable us to create a number of page objects per page and have
them pooled and ready for hits. Especially if a minimum of them aren't
garbage collected later.

For now, I would be more than happy with a semi-proper workaround. If write
something decent, I'll try to contribute it somewhere. 


Angelo Chen wrote:
> 
> Hi Howard,
> 
> The deplay happens before I refer to _userExists, just displaying the page
> takes a long time, you can see from the code below,  the _user field is
> referred to in onSuccess which is after the page display: 
> 
> @ApplicationState
>     private SessionData _user;
> 
>     private boolean _userExists;
> 
>     String onSuccess() {
>   
>    }
> 
> 
> Howard Lewis Ship wrote:
>> 
>> You can inject the ComponentSource into an ApplicationInitializer and
>> obtain
>> the page by name.  There's some other cleanup I can't research now.
>> 
>> It would be interesting to know exactly what is taking so long ... I
>> think
>> you may find it isn't until you reference your _user field that there's a
>> delay, partly to set up the many necessary services, but also to create
>> the
>> HttpSession, which can be time consuming in some servers.
>> 
>> On 9/13/07, Angelo Chen  wrote:
>>>
>>>
>>> Hi Howard,
>>>
>>> I'm quite ok with T5's speed when comes to page display first time, but
>>> it
>>> is really slow when a page contains :  @ApplicationState private
>>> SessionData
>>> _user; loaded first time. Is there a simple way to pre-load that page? 
>>> I
>>> know the page name, dont have to be generic.
>>>
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12669632
Sent from the Tapestry - User mailing list archive at Nabble.com.

Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Howard,

The deplay happens before I refer to _userExists, just displaying the page
takes a long time, you can see from the code below,  the _user field is
referred to in onSuccess which is after the page display: 

@ApplicationState
    private SessionData _user;

    private boolean _userExists;

    String onSuccess() {
  
   }


Howard Lewis Ship wrote:
> 
> You can inject the ComponentSource into an ApplicationInitializer and
> obtain
> the page by name.  There's some other cleanup I can't research now.
> 
> It would be interesting to know exactly what is taking so long ... I think
> you may find it isn't until you reference your _user field that there's a
> delay, partly to set up the many necessary services, but also to create
> the
> HttpSession, which can be time consuming in some servers.
> 
> On 9/13/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>>
>>
>> Hi Howard,
>>
>> I'm quite ok with T5's speed when comes to page display first time, but
>> it
>> is really slow when a page contains :  @ApplicationState private
>> SessionData
>> _user; loaded first time. Is there a simple way to pre-load that page?  I
>> know the page name, dont have to be generic.
>>

-- 
View this message in context: http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12666574
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Martin_S <ma...@gmail.com>.
Oh yeah, you obviously don't need the Hibernate code there.


Angelo Chen wrote:
> 
> Hi Martin,
> 
> Can you share some portion of the code ? I'd like to test it if I can
> speed up my app? Thanks.
> 
> A.C.
> 
> 
> Martin_S wrote:
>> 
>> I have chosen quick-and-dirty for now. like
>> http://www.hibernate.org/114.html, I used a ServletContextListener to
>> detect deployment. For our particular objective, I made it spawn a
>> separate Thread to keep trying (for max one minute) to do a GET of a page
>> that needs to create an HttpSession. 
>> 
>> Tomcat needs you to read at least the first line of a response to obtain
>> the desired behavior.
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12728589
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Martin_S <ma...@gmail.com>.
Add this to web.xml as well:
	<listener>
		<listener-class>
			com.xxxx.tc.util.TapestryListener
		</listener-class>
	</listener>

The attached Java code needs cleanup, but it works.

Angelo Chen wrote:
> 
> Hi Martin,
> 
> Can you share some portion of the code ? I'd like to test it if I can
> speed up my app? Thanks.
> 
> A.C.
> 
> 
> Martin_S wrote:
>> 
>> I have chosen quick-and-dirty for now. like
>> http://www.hibernate.org/114.html, I used a ServletContextListener to
>> detect deployment. For our particular objective, I made it spawn a
>> separate Thread to keep trying (for max one minute) to do a GET of a page
>> that needs to create an HttpSession. 
>> 
>> Tomcat needs you to read at least the first line of a response to obtain
>> the desired behavior.
>> 
>> 
> 
> 
http://www.nabble.com/file/p12728256/TapestryListener.java
TapestryListener.java 
-- 
View this message in context: http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12728256
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Martin,

Can you share some portion of the code ? I'd like to test it if I can speed
up my app? Thanks.

A.C.


Martin_S wrote:
> 
> I have chosen quick-and-dirty for now. like
> http://www.hibernate.org/114.html, I used a ServletContextListener to
> detect deployment. For our particular objective, I made it spawn a
> separate Thread to keep trying (for max one minute) to do a GET of a page
> that needs to create an HttpSession. 
> 
> Tomcat needs you to read at least the first line of a response to obtain
> the desired behavior.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12727957
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Martin_S <ma...@gmail.com>.
It does take longer if an HttpSession has to be created. But the second time
is much faster. I found that accessing even just one page on deployment does
make consecutive access faster. Accessing just one page that needs to create
an HttpSession kills two birds with one stone.

"1st" response times stay short, even hours afterwards (with no other
interaction). I have only tried Tomcat (6.0.13), Jetty(5.1.12 in eclipse) on
Java 1.6.0.0 update 2 and Linux.

I have chosen quick-and-dirty for now. like
http://www.hibernate.org/114.html, I used a ServletContextListener to detect
deployment. For our particular objective, I made it spawn a separate Thread
to keep trying (for max one minute) to do a GET of a page that needs to
create an HttpSession. 

Tomcat needs you to read at least the first line of a response to obtain the
desired behavior.


Howard Lewis Ship wrote:
> 
> You can inject the ComponentSource into an ApplicationInitializer and
> obtain
> the page by name.  There's some other cleanup I can't research now.
> 
> It would be interesting to know exactly what is taking so long ... I think
> you may find it isn't until you reference your _user field that there's a
> delay, partly to set up the many necessary services, but also to create
> the
> HttpSession, which can be time consuming in some servers.
> 
> On 9/13/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>>
>>
>> Hi Howard,
>>
>> I'm quite ok with T5's speed when comes to page display first time, but
>> it
>> is really slow when a page contains :  @ApplicationState private
>> SessionData
>> _user; loaded first time. Is there a simple way to pre-load that page?  I
>> know the page name, dont have to be generic.
>>
>>
>> Howard Lewis Ship wrote:
>> >
>> > Should be possible at startup; there's an ApplicationInitializer chain
>> of
>> > command.
>> >
>> > You have to dive into the internals; ComponentClassResolver would need
>> a
>> > method that could provide the names of all pages.  It knows, but
>> doesn't
>> > currently have an API to share that information.
>> >
>> > Armed with the page names, you would just have to make a bunch of calls
>> to
>> > ComponentSource.getPage(), then perform a little bit of cleanup work
>> (so
>> > that the acquired pages go back into the page pool).
>> >
>> > On 9/13/07, Martin_S <ma...@gmail.com> wrote:
>> >>
>> >>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12665752
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> -- 
> Howard M. Lewis Ship
> Partner and Senior Architect at Feature50
> 
> Creator Apache Tapestry and Apache HiveMind
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12694797
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Howard Lewis Ship <hl...@gmail.com>.
You can inject the ComponentSource into an ApplicationInitializer and obtain
the page by name.  There's some other cleanup I can't research now.

It would be interesting to know exactly what is taking so long ... I think
you may find it isn't until you reference your _user field that there's a
delay, partly to set up the many necessary services, but also to create the
HttpSession, which can be time consuming in some servers.

On 9/13/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>
> Hi Howard,
>
> I'm quite ok with T5's speed when comes to page display first time, but it
> is really slow when a page contains :  @ApplicationState private
> SessionData
> _user; loaded first time. Is there a simple way to pre-load that page?  I
> know the page name, dont have to be generic.
>
>
> Howard Lewis Ship wrote:
> >
> > Should be possible at startup; there's an ApplicationInitializer chain
> of
> > command.
> >
> > You have to dive into the internals; ComponentClassResolver would need a
> > method that could provide the names of all pages.  It knows, but doesn't
> > currently have an API to share that information.
> >
> > Armed with the page names, you would just have to make a bunch of calls
> to
> > ComponentSource.getPage(), then perform a little bit of cleanup work (so
> > that the acquired pages go back into the page pool).
> >
> > On 9/13/07, Martin_S <ma...@gmail.com> wrote:
> >>
> >>
>
> --
> View this message in context:
> http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12665752
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
Partner and Senior Architect at Feature50

Creator Apache Tapestry and Apache HiveMind

Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Howard,

I'm quite ok with T5's speed when comes to page display first time, but it
is really slow when a page contains :  @ApplicationState private SessionData
_user; loaded first time. Is there a simple way to pre-load that page?  I
know the page name, dont have to be generic.


Howard Lewis Ship wrote:
> 
> Should be possible at startup; there's an ApplicationInitializer chain of
> command.
> 
> You have to dive into the internals; ComponentClassResolver would need a
> method that could provide the names of all pages.  It knows, but doesn't
> currently have an API to share that information.
> 
> Armed with the page names, you would just have to make a bunch of calls to
> ComponentSource.getPage(), then perform a little bit of cleanup work (so
> that the acquired pages go back into the page pool).
> 
> On 9/13/07, Martin_S <ma...@gmail.com> wrote:
>>
>>

-- 
View this message in context: http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12665752
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to init T5 pages on deployment? - 1st few hits would be faster

Posted by Howard Lewis Ship <hl...@gmail.com>.
Should be possible at startup; there's an ApplicationInitializer chain of
command.

You have to dive into the internals; ComponentClassResolver would need a
method that could provide the names of all pages.  It knows, but doesn't
currently have an API to share that information.

Armed with the page names, you would just have to make a bunch of calls to
ComponentSource.getPage(), then perform a little bit of cleanup work (so
that the acquired pages go back into the page pool).

On 9/13/07, Martin_S <ma...@gmail.com> wrote:
>
>
> Tapestry 5 currently is slow when a user hits a page for the first time.
> Does anyone know how to make T5 create all page instances at deploy time
> in
> Tomcat? For example, the Hibernate project suggests using a
> ServletContextListener to create a SessionFactory. Something similar would
> be great in T5 to get a better response time when the first user hits a
> page.
> I know just doing requests from a utility class would be a quick-and-dirty
> workaround, but surely there has to be a better way.
> --
> View this message in context:
> http://www.nabble.com/How-to-init-T5-pages-on-deployment----1st-few-hits-would-be-faster-tf4437654.html#a12660957
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
Partner and Senior Architect at Feature50

Creator Apache Tapestry and Apache HiveMind