Skip to main content

Is it appropriate to use Grizzly w/ Tomcat for my webapp?

3 replies [Last post]
syg6
Offline
Joined: 2006-03-16
Points: 0

Hello all.

I would like to know if I should use Grizzly with Tomcat (client already has Tomcat, otherwise I'd switch to GlassFish!) for the project I am doing. What I have is a normal webapp -- jsps, Actions, database, etc.

What I'd like to do is put an XML cache server just behind the web server. This XML cache server will:

1. Look to see if the info is already in the cache.
2. If it is, return it, without having to query the database.
3. If not, the petition is passed on as normal, queries the database, then adds the info to the cache.
4. It then opens up a socket to another machine with the same setup -- web server, XML cache server -- and sends the info so that machine now has the info in its cache as well.

I think I need to use NIO, since doing it without out NIO would mean a socket/thread for each petition. So I made a servlet which creates a simple NIOServer (which contains an object SelectorThread with its own Selector and Thread) and another SelectorThread to be used by each NIOClient.

Upon receiving an HTTP request, I save the info sent to me in the request, make a new NIOClient, passing it the client SelectorThread, and send the info to another server.

It works but using JMeter, when I get up around 2,000 concurrent requests it poops the bed -- memory problems, blocked ports, etc.

Sooooo my question is, could I possibly plug in Grizzly to my Tomcat instead of Coyote, and use its ARP, as Jean-Francois Arcand explains in his blog? He says it'sa appropriate "when a business process is calling out to another one over a slow protocol". In my case I'll eventually serializing these XMLs, so even though they are small it will be a bottleneck.

Would I gain anything by using Grizzly? Anyone ever done something like this before?

Many many thanks!
Bob

But with NIO it seems to be working ok. I have a servlet with a static Server (with its SelectorThread) and also another static SelectorThread for the Client. Each time there is a petition I create a new Client and pass it my Client Selector Thread.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jfarcand
Offline
Joined: 2003-06-10
Points: 0

Hi Bob,

answering your first question, it might be easier to use Grizzly insdide GlassFish, althrough it is not difficult to put Grizzly in front of Tomcat (I will blog about it soon).

From the description you included, ARP is a good solution. From ARP, you can always get temporary Grizzly's Selector to handle your OP_CONNECT operation (when connecting to another server), so Grizzly can also take care of your connect operations.

I also think you can use the Grizzly build-in static resource cache for your xml so NIO will be used without having to enter the Servlet Container. The performance of the file cache is quite impressive :-)

I recommend you start with GlassFish b41, and you can probably start by writting your own AsyncFilter and most probably building on top of:

http://weblogs.java.net/blog/jfarcand/archive/2006/02/grizzly_part_ii.html

Feel free to use this thread or the blof for any questions :-)

Thanks!

-- Jeanfrancois

syg6
Offline
Joined: 2006-03-16
Points: 0

Hello Jeanfrancois, thanks for the reply.

Well, I am into the idea of using Grizzly but not clear on the details.

In terms of using Grizzly's Selector to connect to the other cache servers, I'm not sure how I would be able to tell Grizzly - "hey, look this up in the local cache server, it it's not there, get it from the database, store it, send it on to the next machine AND send back a NORMAL HTTP Response with the results of the database lookup."

My hopes and fears are the following:

1. Not ALL HTTP Requests will be candidates for cacheing. Therefore, how can I tell Grizzly ONLY to handle certain Requests?

2. If the data ISN'T in the local cache and I have let the HTTP Request do its normal work -- go to the database, look up the info -- I then need to grab the Response, store that info in the local cache, send it to another cache server via NIO, AND THEN send back the normal HTTP Response, all of this transparently and quickly. Is this possible? Can you give me some more details as to how I'd go about this?

In terms of using Grizzly's File cache, we already have a system designed (not implemented) for storing our info. We are going to Serialize the XML info as very small classes on the servers's file system. Thus I don't think I can take advantage of Grizzly's file cache. Or can I?

I have been playing with various NIO applications -- EmberIO and EJOE mostly -- and well ... they all have their pluses (EJOE seems easy to use and development is ongoing, EmberIO seems quite powerful) and minuses (EJOE examples don't seem to work out of the box and the javadocs don't correspond to the release, EmberIO seems like a dead project and is kind of difficult to understand, both have almost non-existent documentation) so it's hard to know which way to go.

Using Grizzly might save me the trouble, but I need a little direction from a pro.

Thanks for any help!
Bob

jfarcand
Offline
Joined: 2003-06-10
Points: 0

Hi Bob,

You gonna use the Grizzly Selector to register your OP_CONNECT (client socket) to connect to your other servers. This way it will sacle better if you use non blocking for connecting to your servers. You still need to implement the logic for connecting, but keep in mind you can use a temporary Selector to register your connection.

Question 1: You gonna write an AsyncFilter where you will implement the appropriate logic for filtering your requests. If some requests doesn't need to be filterred, then you can execute it using synchonously.

Question 2: Take a look at the NoParsingHandler logic. You gonna need to write your own handler, which will have the chance to trap the response and cache it, like the NoParsingHandler is doing with static resource.

Yes you can cache your serialized XML using the FileCache, because it is static resource.

You can take a look at the Mina framework (http://directory.apache.org/subprojects/mina/index.html) as an alternative for EmberIO. Of course I would prefer you use Grizzly :-)

-- Jeanfrancois