[CONF] Apache Tapestry Page Lifecycle

2010-11-26 Thread confluence







Page Lifecycle
Page
comment added by  Bob Harner



   I believe this page needs to be rewritten for the new approach in 5.2 of not pooling pages.  This will nee dto be done by someone with a better understanding of the mechanisms involved than I have.




   
Change Notification Preferences
   
   View Online
   









[CONF] Apache Tapestry Page Lifecycle

2010-11-26 Thread confluence







Page Lifecycle
Comment edited by Bob Harner
 :

Changes (1)




I believe this page needs to be rewritten for the new approach in 5.2 of _not_ pooling pages.  This will nee d to be done by someone with a better understanding of the mechanisms involved than I have. 

Full Content
  
I believe this page needs to be rewritten for the new approach in 5.2 of not pooling pages.  This will need to be done by someone with a better understanding of the mechanisms involved than I have.



   
Change Notification Preferences
   
   View Online
   









[CONF] Apache Tapestry Page Lifecycle

2010-06-16 Thread confluence







Page Lifecycle
Page  added by Ulrich Stärk

 

 Page Lifecycle

In Tapestry, you are free to develop your presentation objects, page and components classes, as ordinary objects, complete with instance variables and so forth.

This is somewhat revolutionary in terms of web development in Java. Using servlets, or Struts, your presentation objects (Servlets, or Struts Actions, or the equivalent in other frameworks) are stateless singletons. That is, a single instance is created, and all incoming requests are threaded through that single instance.

Because multiple requests are handled by many different threads, this means that the single instance's variable are useless ... any value written into an instance variable would immediately be overwritten by a different thread. Thus, it is necessary to use the Servlet API's HttpServletRequest object to store per-request data, and the HttpSession object to store data between requests.

Tapestry takes a very different approach.

In Tapestry, you will have many different instances of any particular page, each either in use for a single request (on a single thread), or waiting in a page pool to be used.

By reserving page instances to particular threads, all the difficult, ugly issues related to multi-threading go by the wayside. Instead, familiar, simple coding practices (using ordinary methods and fields) can be used.

However, there's a risk: it would be a disaster if data could "bleed" from one request to another. Imagine the outcome in a banking application if the first user's account number and password became the default for the second user to reach the application!

Tapestry takes special care to purge all instance variables back to their default value at the end of each request.

The end result is that all pages in the pool are entirely equivalent to each other; it doesn't matter which instance is used for processing any particular request.

Remember that the page instance is just the tip of the iceberg: a page instance encompasses the page component, its templates, all of its parameter bindings, tokens read from its template and (recursively) the same thing for all components inside the page. It adds up.

A page instance will be "checked out" of the pool for a short period of time: a few milliseconds to service a typical request. Because of this, it is generally the case that Tapestry can handle a large number of end users with a relatively small pool of page instances.

Comparison to JavaServer Pages

JSPs also use a caching mechanism; the JSP itself is compiled into a Java servlet class, and acts as a singleton.

However, the individual JSP tags are pooled.

This is one of the areas where Tapestry can significantly outperform JSPs. Much of the code inside a compiled JSP class concerns getting tags from a tag pool, configuring the properties of the tag instance, using the tag instance, then cleaning up the tag instance and putting it back in the pool.

The operations Tapestry does once per request are instead executed dozens or potentially hundreds of times (dependending the complexity of the page, and if any nested loops occur).

Pooling JSP tags is simply the wrong granularity.

Tapestry can also take advantage of its more coarse grained caching to optimize how data moves, via parameters, between components. This means that Tapestry pages will actually speed up after they render the first time.

Page Pool Configuration

Tapestry's page pool is used to store page instances. The pool is "keyed" on the name of the page (such as "start") and the locale for the page (such as "en" or "fr").

Within each key, Tapestry tracks the number of page instances that have been created, as well as the number that are in use (currently attached to a request).

When a page is first accessed in a request, it is taken from the pool. Tapestry has some configuration values that control the details of how and when page instances are created.


	If a free page instance is available, the page is marked in use and attached to the request.
	If there are fewer page instances than the soft limit, then a new page instance is simply created and attached to the request.
	If the soft limit has been reached, Tapestry will wait for a short period of time for a page instance to become available before creating a new page instance.
	If the hard limit has been reached, Tapestry will throw an exception rather than create a new page instance.
	Otherwise, Tapestry will create a new page instance.
Thus a busy application will initially create pages up-to the soft limit (which defaults to five page instances). If the application continues to be pounded with requests, it will slow its request processing, using the soft wait time in an attempt to reuse an existing page instance.



A truly busy application will continue to create new page instances as needed until the hard limit is reached.

Remember that all these configuration values are per key: