tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Danilo Luiz Rheinheimer <danilo...@yahoo.com>
Subject Re: Performace - long time to release connection
Date Wed, 16 Apr 2008 16:25:41 GMT
Jim,

  Thanks for your help.

I am not setting the content-length on my servlet
code.
But if I see the response headers (using firebug) I
have this result :

Content-Length: 4332
Content-Type: text/html

But another tool I have show me the page size as 4276.

If I print the size of my response with :

s.getBytes().length

(where s is my response, see code on previous message)

I get the value 4276.
So I think you can be right on the cause of the
problem.

But how is the right way of set the content lenght ?

I try this :

// other data headers
response.setDateHeader ("Expires", 0);
response.setContentType("text/html");
String s = ... // creates JSON String
response.setContentLength(s.getBytes().length);
PrintWriter w = response.getWriter();
w.write(s);
response.setStatus(HttpServletResponse.SC_OK);

The problem still happens.

Then I try this :

byte[] data = s.getBytes();
            
response.setContentLength(data.length);
    		
ServletOutputStream ouputStream =
response.getOutputStream();
ouputStream.write(data, 0, data.length);    		
ouputStream.flush();
ouputStream.close();           
response.setStatus(HttpServletResponse.SC_OK);

But still no solution.
The response header keep showing Content-Length=4332.

How I can set the Content-Length in a reliable way ?
>From where this 4332 value comes from ?

Danilo.

--- Jim Cox <shakahshakah@gmail.com> wrote:

> Does the client get a "Content-length" header, and
> if so does the actual
> length of the response body match? If not it has to
> either timeout or wait
> for the server to close the connection.
> 
> On Wed, Apr 16, 2008 at 11:33 AM, Danilo Luiz
> Rheinheimer <
> danilo_lr@yahoo.com> wrote:
> 
> > Hi,
> >
> >  I have a Java application running on a Tomcat
> server
> > (last version of the 5.5 serie). Java version is
> 6.
> >  I have a servlet inside this application who
> returns
> > json to the browser (if you do not know json it is
> > just a text).
> >  This process it taking a very long time,
> something
> > like  10 seconds.
> >  I put some simple debug code inside my servlet to
> > show how much time the servlet takes to process
> it.
> > The time is short like 0.5 seconds.
> >  Still to the browser it takes 10 seconds !
> >  If I type the servlet url on the browser I can
> see
> > it returns the result fast (the json shows on the
> > browser screen after 0.5 seconds).
> >  But it do not release the http connection to the
> > server. It keeps the message 'receiving data from
> ...'
> > on the botton of the browser for almost 10
> seconds.
> >  There are not a big load on the server at the
> moment
> > of this tests. In fact it is only me.
> >
> >  The resumed servlet code is something like this :
> >
> >       
> response.setHeader("Cache-Control","no-cache");
> >        response.setHeader("Pragma","no-cache");
> >        response.setDateHeader ("Expires", -1);
> >       
> response.setHeader("Cache-Control","no-store");
> >        response.setDateHeader ("Expires", 0);
> >
> >        response.setContentType("text/html");
> >
> >        String s = ... // creates JSON String
> >        PrintWriter w = response.getWriter();
> >        w.write(s);
> >
> >  As you can see very standard I think.
> >  I have the no cache headers because the json is
> > generated at every time and can not be cahed.
> >
> >  Someone has any idea of what the problem is ?
> >
> > Danilo.
> >
> >
> >
> > 
>
____________________________________________________________________________________
> > Be a better friend, newshound, and
> > know-it-all with Yahoo! Mobile.  Try it now.
> >
>
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> >
> >
>
---------------------------------------------------------------------
> > To start a new topic, e-mail:
> users@tomcat.apache.org
> > To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail:
> users-help@tomcat.apache.org
> >
> >
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message