You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kai Müller <km...@mediadom.de> on 2000/11/27 12:46:40 UTC

Re: Increasing memory problem

Hello Shuklix,

could you tell me more about the thread pooling, please? Where do I get some
information? How does Tomcat handle the requests?

Thank you.

Kai

Saurabh Shukla wrote:

> YOu can also try Thread Pooling in tomcat, it might be help.
>
> SHuklix
>
> -----Original Message-----
> From: Julio Serje (@canada.com) [mailto:jserje@home.com]
> Sent: Sunday, November 26, 2000 10:08 PM
> To: tomcat-user@jakarta.apache.org; km@mediadom.de
> Subject: Re: Increasing memory problem
>
> Hi, Kai.
>
> The problem you are experiencing is a difficult one, as it relates to the
> way you allocate and de-allocate your resources in a way the garbage
> collector can determine that a resource is not needed anymore.
>
> You say that you're using jdbc. You should make sure that you are properly
> (and explicitly) deallocating all resources you create.
>
> a) Connections to the database. If you're not using a connection pool, make
> sure your connections are closed.
> b) ResultSets AND statements. This is a common problem, you must close()
> them in order to let the garbage collector do its work.
> example:
> rset.close();
> stmt.close();
> conn.close();
>
> Julio
>
> ----- Original Message -----
> From: Kai Müller <km...@mediadom.de>
> To: <to...@jakarta.apache.org>
> Sent: Friday, November 24, 2000 12:35 PM
> Subject: Increasing memory problem
>
> > Hi everybody!
> >
> > My problem is the following:
> >
> > after I start my application (JSPs read from MySQL) with Tomcat 3.1 the
> > used memory of the java processes increases and the number of java
> > processes themselves increases if I reload the same site (2 per second),
> > reload, reload, reload .... ;-)
> >
> > The performance goes down, and sometimes Tomcat crashes. The HTML sent
> > to the browser is large (about 350 kB). I get several errors
> > (OutOfMemory, Response has already been committed,...) and I am
> > absolutely confused about it now.
> >
> > Can anybody help me ? Do you need further information ?
> >
> > With kind regards
> >
> > Kai Müller
> >
> >
> > The input.jsp is the following and a global entry for all requests,
> > which are handled and forward on a JSP page with the HTML-Codes.
> >
> > ----------------------------------------------------
> > <%@ page errorPage="/error/errorpage.jsp" %>
> > <%@ page import="javax.servlet.*" %>
> > <%@ page import="javax.servlet.http.*" %>
> >
> > <%
> >    response.setDateHeader("Expires",0);
> >    response.setHeader("Pragma","no-cache");
> >    response.setHeader("Cache-Control","no-cache,must-revalidate");
> > %>
> >
> >  <jsp:useBean
> >    id="requestProc"
> >    class="TheRequestClass"
> >    scope="session"
> >  >
> > <%
> >      requestProc.initialize(config.getServletContext(), session);
> >  %>
> > </jsp:useBean>
> >
> >  <jsp:useBean
> >    id="pageController"
> >    class="ThePageControllerClass"
> >    scope="session"
> >  >
> > </jsp:useBean>
> >
> >
> >  <%
> >    requestProc.processRequest(request);
> >
> >    String next = pageController.getNextPage(request);
> >    getServletConfig().getServletContext().getRequestDispatcher("/" +
> > next).forward(request, response);
> >  %>
> > -----------------------------------------------------
> > --
> >
> > Mediadom audiovisuelle Medien GmbH
> > Merheimer Str. 151
> > D-50733 Koeln
> >
> > Tel.: 0221 / 917 11 80
> > Fax: 0221 / 917 11 81
> >
> > Internet: http://www.mediadom.de
> >
> >

--

Mediadom audiovisuelle Medien GmbH
Merheimer Str. 151
D-50733 Koeln

Tel.: 0221 / 917 11 80
Fax: 0221 / 917 11 81

Internet: http://www.mediadom.de



Re: Increasing memory problem (i hope this helps)

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
See below.

Saurabh Shukla wrote:

> >could you tell me more about the thread pooling, please? Where do I get
> some
> >information? How does Tomcat handle the requests?
>
> >Thank you.
>
> >Kai
>
> I hope this helps.
>
> The PROBLEM:
> Tomcat is a multi-threaded servlet container, this means that the requests
> needs to be executed by some thread, when a new requests arrives a new
> thread
> starts and serves the request. This is very problmatic coz' of this it is
> hard
> to limit the resource consumptio, i.e if 300 requests arrive concurrently
> tomcat will open 300 threads and serve them, this causes tomcat to allocate
> more resources(CPU, memory,..) than it should and leads to low performance
> and
> crashes.(for that matter memory problems with Oracle were coz' of this).
>
> THE SOLUTION: Having a thread pool, instead of allocating new threadsl
> whenvever they need a thread they ask for it from the pool and and when they
> are done
> the thread is returned to the pool. Thread management techniques such as:
>
> 1) Keeping threads open and reusing them over and over again, this saves
> trouble associated with creating and destructing threads continuously.
>
> 2) setting an upper bound on the number of concurrent threads used, this
> solves the resource allocation problem.
>
> Shuklix
> ----------------------------------------------------------------------------
> ----
>
> Ps: This is a excerpt from a write up which i had read,  had kept this
>     a small write up for my reference.   Sorry author for not being able to
> give
>     you due credit.
> ----------------------------------------------------------------------------

To amplify this explanation slightly:  Tomcat allows you to configure the use of
a thread pool, and limit the maximum number of simultaneous requests by limiting
the maximum number of threads that are allowed in the pool.  The details of how
to do this (in server.xml) depend on which version of Tomcat you are talking
about.

It actually makes no functional difference to your applications whether Tomcat
is using a thread pool or creating threads on the fly -- the only differences
will be performance related.  In particular, you can limit the total number of
threads even if you are creating them on the fly, by simply maintaining a
reference count of how many active threads there are, and refusing to create one
if you are at the maximum already.

But, that all being said, threads are the servlet container's problem to
manage.  The application developer, thankfully, needs to worry only about their
application (including the fact that a particular servlet can be accessed by
more than one thread at the same time -- but you don't have to worry about *how*
that happens).

Craig McClanahan





RE: Increasing memory problem (i hope this helps)

Posted by Saurabh Shukla <sa...@cysphere.com>.

>could you tell me more about the thread pooling, please? Where do I get
some
>information? How does Tomcat handle the requests?

>Thank you.

>Kai

I hope this helps.

The PROBLEM:
Tomcat is a multi-threaded servlet container, this means that the requests
needs to be executed by some thread, when a new requests arrives a new
thread
starts and serves the request. This is very problmatic coz' of this it is
hard
to limit the resource consumptio, i.e if 300 requests arrive concurrently
tomcat will open 300 threads and serve them, this causes tomcat to allocate
more resources(CPU, memory,..) than it should and leads to low performance
and
crashes.(for that matter memory problems with Oracle were coz' of this).

THE SOLUTION: Having a thread pool, instead of allocating new threadsl
whenvever they need a thread they ask for it from the pool and and when they
are done
the thread is returned to the pool. Thread management techniques such as:

1) Keeping threads open and reusing them over and over again, this saves
trouble associated with creating and destructing threads continuously.

2) setting an upper bound on the number of concurrent threads used, this
solves the resource allocation problem.


Shuklix
----------------------------------------------------------------------------
----

Ps: This is a excerpt from a write up which i had read,  had kept this
    a small write up for my reference.   Sorry author for not being able to
give
    you due credit.
----------------------------------------------------------------------------
----
Hello Shuklix,

could you tell me more about the thread pooling, please? Where do I get some
information? How does Tomcat handle the requests?

Thank you.

Kai

Saurabh Shukla wrote:

> YOu can also try Thread Pooling in tomcat, it might be help.
>
> SHuklix
>
> -----Original Message-----
> From: Julio Serje (@canada.com) [mailto:jserje@home.com]
> Sent: Sunday, November 26, 2000 10:08 PM
> To: tomcat-user@jakarta.apache.org; km@mediadom.de
> Subject: Re: Increasing memory problem
>
> Hi, Kai.
>
> The problem you are experiencing is a difficult one, as it relates to the
> way you allocate and de-allocate your resources in a way the garbage
> collector can determine that a resource is not needed anymore.
>
> You say that you're using jdbc. You should make sure that you are properly
> (and explicitly) deallocating all resources you create.
>
> a) Connections to the database. If you're not using a connection pool,
make
> sure your connections are closed.
> b) ResultSets AND statements. This is a common problem, you must close()
> them in order to let the garbage collector do its work.
> example:
> rset.close();
> stmt.close();
> conn.close();
>
> Julio
>
> ----- Original Message -----
> From: Kai Müller <km...@mediadom.de>
> To: <to...@jakarta.apache.org>
> Sent: Friday, November 24, 2000 12:35 PM
> Subject: Increasing memory problem
>
> > Hi everybody!
> >
> > My problem is the following:
> >
> > after I start my application (JSPs read from MySQL) with Tomcat 3.1 the
> > used memory of the java processes increases and the number of java
> > processes themselves increases if I reload the same site (2 per second),
> > reload, reload, reload .... ;-)
> >
> > The performance goes down, and sometimes Tomcat crashes. The HTML sent
> > to the browser is large (about 350 kB). I get several errors
> > (OutOfMemory, Response has already been committed,...) and I am
> > absolutely confused about it now.
> >
> > Can anybody help me ? Do you need further information ?
> >
> > With kind regards
> >
> > Kai Müller
> >
> >
> > The input.jsp is the following and a global entry for all requests,
> > which are handled and forward on a JSP page with the HTML-Codes.
> >
> > ----------------------------------------------------
> > <%@ page errorPage="/error/errorpage.jsp" %>
> > <%@ page import="javax.servlet.*" %>
> > <%@ page import="javax.servlet.http.*" %>
> >
> > <%
> >    response.setDateHeader("Expires",0);
> >    response.setHeader("Pragma","no-cache");
> >    response.setHeader("Cache-Control","no-cache,must-revalidate");
> > %>
> >
> >  <jsp:useBean
> >    id="requestProc"
> >    class="TheRequestClass"
> >    scope="session"
> >  >
> > <%
> >      requestProc.initialize(config.getServletContext(), session);
> >  %>
> > </jsp:useBean>
> >
> >  <jsp:useBean
> >    id="pageController"
> >    class="ThePageControllerClass"
> >    scope="session"
> >  >
> > </jsp:useBean>
> >
> >
> >  <%
> >    requestProc.processRequest(request);
> >
> >    String next = pageController.getNextPage(request);
> >    getServletConfig().getServletContext().getRequestDispatcher("/" +
> > next).forward(request, response);
> >  %>
> > -----------------------------------------------------
> > --
> >
> > Mediadom audiovisuelle Medien GmbH
> > Merheimer Str. 151
> > D-50733 Koeln
> >
> > Tel.: 0221 / 917 11 80
> > Fax: 0221 / 917 11 81
> >
> > Internet: http://www.mediadom.de
> >
> >

--

Mediadom audiovisuelle Medien GmbH
Merheimer Str. 151
D-50733 Koeln

Tel.: 0221 / 917 11 80
Fax: 0221 / 917 11 81

Internet: http://www.mediadom.de