dev@grizzly.java.net

issue with suspend request

From: <rama.rama_at_tiscali.it>
Date: Thu, 16 Apr 2009 16:14:27 +0200 (CEST)

yo!

i am always here to bother you :)

i have noticed something of
strange with suspend request.


A little of history before
1) i was
using an async filter to suspend certain kind of request
2) after see
the suspend/resume possibility, i have try to switch to this kind of
approach

the approach 1 is working perfectly right now (but i like to
try new stuff)

the approach 2, seem to trash all the memory :(


writing a test case, have come up with this stuff


Basically what the
test case do is
1) create a WS
2) add an adapter
3) start

the adapter
do
1) create a thread
2) get a request, if the req is not suspended,
then suspend it and add to the queue
3) the thread in background simply
resume the response

Using firefox i get "bau" reply without error

using "ab -c 100 -n 1000" i am not able to finish the test

for this
reason test the memory problem isn't easy, but i am pretty sure that
there is something there, because, after removing the suspend/resume
from the whole system, memory usage come back to normally use.

Also i
am sure that all request that i add to "queue" are correctly resumed
(after a max of 20sec on the real case of usage)

using grizzly 1.9.13
:)

best regards

----code---

import com.sun.grizzly.http.embed.
GrizzlyWebServer;
import com.sun.grizzly.tcp.CompletionHandler;
import
com.sun.grizzly.tcp.http11.GrizzlyAdapter;
import com.sun.grizzly.tcp.
http11.GrizzlyRequest;
import com.sun.grizzly.tcp.http11.
GrizzlyResponse;

import java.util.concurrent.LinkedBlockingQueue;

import java.util.concurrent.TimeUnit;

public class test {
        
public static void main( String arg[] ) throws Exception {
            
GrizzlyWebServer ws = new GrizzlyWebServer();
            ws.
getSelectorThread().setDisplayConfiguration(true);
            ws.
addGrizzlyAdapter(new testGW());
            ws.start();
        }
}


class testGW extends GrizzlyAdapter {
    SP t = new SP();

    public
void service(final GrizzlyRequest grizzlyRequest, final GrizzlyResponse
httpResp) {
            if (!httpResp.isSuspended()) {

                    httpResp.suspend(Integer.MAX_VALUE,this,new
CompletionHandler<testGW>() {
                        public void
resumed(testGW attachment) {
                             try {

                                 attachment.service(grizzlyRequest,
httpResp);
                             } catch (Exception e) {


                             }
                         }

                         public void cancelled(testGW attachment) {

                             throw new Error("Request cancelled?!?");

                         }
                    });
                    
t.add(httpResp);
                    return;
            }
            
try {
                String error = "bau";
                httpResp.
setContentLength(error.length());
                httpResp.
setContentType("text/html");
                httpResp.setStatus(404);

                httpResp.getWriter().print(error);
            } catch
(Exception e) {

            }
    }
}
class SP extends Thread {

    
LinkedBlockingQueue<GrizzlyResponse> v = new
LinkedBlockingQueue<GrizzlyResponse>();
    public void add
(GrizzlyResponse httpResp) {
            v.add(httpResp);
    }
    
public SP() {
        this.start();
    }
    public void run() {

        while (true) {
            try {
                
GrizzlyResponse e = v.poll(10, TimeUnit.SECONDS);
                if
(e==null) continue;
                Thread.sleep(10);
                e.
resume();
            } catch (InterruptedException e1) {
            }

        }
    }
}


----
Arriva Tiscali Mobile! Acquista la tua SIM Tiscali a soli €5 e scopri la semplicità e la convenienza del nuovo servizio per il tuo cellulare. 
Passa a Tiscali Mobile http://abbonati.tiscali.it/promo/tiscalimobile/