users@glassfish.java.net

Re: App Server Complete Deadlock Occurs When HTTP Thread Limit Reached

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Tue, 10 Jul 2007 15:33:13 -0400

Hi,

my first investigation was right :-) You are flooding the server by
invoking a
Servlet that invoke back the GlassFish http-listener and indefinitively
waits
for a response, reserving a thread for that operation. So if you send 5
requests, it means all the 5 threads running your Servlet will eat the 5
threads, waiting for a response. Since the 5 available threads are
already used,
the request will be polled (so you have the feeling that GlassFish
hangs). Try
it with Tomcat and Jetty (set their number of threads = 5) and you will
get the
same behavior.

You can see GlassFish is not hanging by changing the request queue size:

<connection-pool max-pending-count="4096" queue-size-in-bytes="100"
receive-buffer-size-in-bytes="4096" send-buffer-size-in-bytes="8192"/>

Set it to 100 and run the following:

java -cp j2ee.jar:dest/lib/MyServlet.jar servlet.MyServlet
http://localhost:8080/s1?url=http://localhost:8080/s2 500

You will see GlassFish reject requests. Also the connection you are opening
never times out. Just add uc.setConnectTimeout(5000); and you will never
experience a hangs (normally you should always make sure your
connections times
out after a x times, usually 30 seconds).

Increasing the number of threads or acceptor-threads will just delay the
problems with your application.

Thanks

-- Jeanfrancois

glassfish_at_javadesktop.org wrote:
> Hi.
>
> There is indeed a maximum of five processing threads (checked on Glassfish V2B54)
> This small servlet launched from for example IE shows that after five connections new connections are waiting.
> Worse, if you launch about 50 connections at the same time, the listener is definitly dead.
>
> Incrementing the Acceptor Threads in glassfish console to 500 seems to allow 50 (exactly) conncurrent connections. No idea why...
>
> ------------------------------
> protected void processRequest(HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException {
> response.setContentType("text/html;charset=UTF-8");
> PrintWriter out = response.getWriter();
>
> for(int i = 0; i < 60; i++) {
> out.write("BIP " + Integer.toString(i) + "\n\r");
> out.flush();
> try {
>
> Thread.sleep(1000);
> } catch (InterruptedException ex) {
> ex.printStackTrace();
> }
> }
>
> out.close();
> }
> ----------------------------------------------------------------------------------
>
> // this code kills the glassfish http listener forever
> public class BipReader extends Thread {
>
> /** Creates a new instance of BipReader */
> public static void main(String[] args) throws Exception {
> for(int i= 0; i <150; i++)
> new BipReader().start();
> }
>
> public void run() {
> try {
> URL url = new URL("http://192.17.1.170:8088/BipServlet/BipServlet");
> InputStream in = url.openStream();
> while(true) {
> int c = in.read();
> if(c == -1)
> break;
> else
> System.out.print((char) c);
> }
> }
> catch(Exception e) {}
> }
> }
> [Message sent by forum member 'alpha1' (alpha1)]
>
> http://forums.java.net/jive/thread.jspa?messageID=225894
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>