dev@grizzly.java.net

still some help for grizzlywebserver

From: rama <rama.rama_at_tiscali.it>
Date: Wed, 24 Dec 2008 00:24:48 +0100

Hi to all :)

1st of all, marry xmas and happy new year :D

ok, now that is done with formality i have some questions :)


the problem: some client take up to 3 mins to get a big file.

Idea for solution: use asyncwrite, set it and forget it :D

the prolem number 2: it doesn't work :D


let's start with questions.

1) i use this constructor

*****
      public GrizzlyWebServer(int port, int maxThreads, String
webResourcesPath,
              boolean secure) {
          createSelectorThread(port, maxThreads, secure);
          this.webResourcesPath = webResourcesPath;
      }
*****

to create the webserver (cos i need ssl support)
specify maxThreads > 5 doesn't add any worker :S

Basically, i want to have more worker that will be able to serve the
client, so if a client
take a lot of time to get the response, other will not be blocked.

Also, a nice things, that probably is there but i don't get, is to
create
worker thread based on the load or the real needing.

How i can add this?


2) async write
****
    public void useAsynchronousWrite(boolean asyncWrite){
         st.setAsyncHttpWriteEnabled(asyncWrite);
    }
****
if i turn this on, i got some wired response :(
basically the client is a flash program, that do some loadmovie.
Sometimes the flash get corrupted in the transfer and flash crash
with pain and suffering.
removing the asyncwrite fix the problem :) honestly i don't know how
i can debug it :(

but i have some info to give to you :D

this is what i do to write the response, i have 2 different case
a) the request is a POST, i parse the request and generate an XML as
a response then, to write it
****
         httpResp.setHeader("Set-Cookie", "SID="+session.sid);
          httpResp.setCharacterEncoding("utf-8");
          httpResp.setStatus(200);
          httpResp.setContentType("text/xml");
          httpResp.getWriter().print(res.asXML());
****

res.asXML return a string, so for me is ok, isn't it??
I haven't tested too much this part with asyncwrite, because the
flash crash before (while loading a swf)

b) the request is a GET, so i send out a file
i don't use staticresadapter, for some odd reason i need to get the
file in 2 different place (i know that this is horrible, but at the
moment is the only way)
and, to write the file out, i do
****
                  //SEND FILE
                    res.setStatus(200);

                         int dot = resource.getName().lastIndexOf(".");
                         if (dot > 0) {
                                 String ext = resource.getName
().substring(dot + 1);
                                 String ct = MimeType.get(ext);
                                 if (ct != null) {
                                         res.setContentType(ct);
                                 }
                         } else {
                                 res.setContentType(MimeType.get
("html"));
                         }

                         long length = resource.length();
                         res.setContentLengthLong(length);

                         fis = new FileInputStream(resource);
             byte b[] = new byte[8192];
             while (fis.read(b) > 0) {
                 res.getStream().write(b);
             }
             res.getStream().flush();
****

keep in mind that res is a grizzlyresponse in this example.
could this piece of code generate some problem with asyncwrite?


Tnx for your assistance :)