Re: Per context heap usage

2022-05-19 Thread Christopher Schultz

Robert,

On 5/19/22 02:34, Robert Olofsson wrote:

On Wed, 2022-05-18 at 17:36 -0400, Christopher Schultz wrote:

Is it possible to find out the per deployed context heap usage in
tomcat?


With a profiler you can look at the retained size of the web
application class loader instance associated with a web application.



What reference path would lead from a java.lang.String object to the web
application ClassLoader? It's allocation-path? That would be tied to the
Thread which allocated it, not to the TCCL the Thread happened to have
at the time.


If you look at a memory dump you can follow the references both up and down
Going up means asking "who owns this object" or "what class keeps this object
alive".
Going down means asking "What fields does this class hold"

With modern memory profilers you can aks for the retained set of objects,
the profiler will then start from the root objects and go down and calculate
how much memory is hanging under each object. Since the jvm heap is a
graph with circles this is a bit tricky, but that is for the profile writers
to figure out.

So if we look at a hypothetical example:
Tomcat holds references to one or more classloaders, one per webapp.
Each such classloader holds on to a set of servlets.
Each servlet holds on to its own resources.

So when you look at the retained sets you se something like:
Tomcat holds 100% of the memory
  - Classloader for webapp 1 holds 80% of the memory
   - Servlet A holds 79% of the memory
   - Servlet B holds 1% of the memory
  - Classloader for webapp 2 holds 15% of the memory
  - classloader for webapp 3 holds 5% of the memory


This is of course a simplified example and common things may make the
statistics hard to read.

Personally I have used both visualvm and eclipse mat to look at memory
profiles. Both of them support retained set calculations, but with the
last releases of java I have only managed to get visualvm working well.
If you get eclipse mat working with this it tends to be a bit more helpful.

Hope that makes sense!


It does. Thatnks for pointing-out that, in order for the (e.g. String) 
object to reachable, it must have a reference being held by something 
else -- and that something was loaded either directly or indirectly from 
the webapp classloader. Duh.


-chris

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Per context heap usage

2022-05-19 Thread Robert Olofsson
On Wed, 2022-05-18 at 17:36 -0400, Christopher Schultz wrote:
> > > > > Is it possible to find out the per deployed context heap usage in 
> > > > > tomcat?
> > > > 
> > > > With a profiler you can look at the retained size of the web 
> > > > application class loader instance associated with a web application.
> > > 
> What reference path would lead from a java.lang.String object to the web 
> application ClassLoader? It's allocation-path? That would be tied to the 
> Thread which allocated it, not to the TCCL the Thread happened to have 
> at the time.

If you look at a memory dump you can follow the references both up and down
Going up means asking "who owns this object" or "what class keeps this object
alive". 
Going down means asking "What fields does this class hold"

With modern memory profilers you can aks for the retained set of objects, 
the profiler will then start from the root objects and go down and calculate
how much memory is hanging under each object. Since the jvm heap is a 
graph with circles this is a bit tricky, but that is for the profile writers
to figure out.

So if we look at a hypothetical example:
Tomcat holds references to one or more classloaders, one per webapp.
Each such classloader holds on to a set of servlets.
Each servlet holds on to its own resources.

So when you look at the retained sets you se something like:
Tomcat holds 100% of the memory
 - Classloader for webapp 1 holds 80% of the memory
  - Servlet A holds 79% of the memory
  - Servlet B holds 1% of the memory
 - Classloader for webapp 2 holds 15% of the memory
 - classloader for webapp 3 holds 5% of the memory


This is of course a simplified example and common things may make the
statistics hard to read.

Personally I have used both visualvm and eclipse mat to look at memory 
profiles. Both of them support retained set calculations, but with the
last releases of java I have only managed to get visualvm working well.
If you get eclipse mat working with this it tends to be a bit more helpful.

Hope that makes sense!

/robo

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Per context heap usage

2022-05-18 Thread Christopher Schultz

Mark,

On 5/17/22 12:50, Mark Thomas wrote:

On 17/05/2022 17:34, Christopher Schultz wrote:

Mark,

On 5/17/22 08:17, Mark Thomas wrote:

On 17/05/2022 10:41, Thomas Meyer wrote:

Hi,

Is it possible to find out the per deployed context heap usage in 
tomcat?


With a profiler you can look at the retained size of the web 
application class loader instance associated with a web application.


I don't think this will tell you the volume of objects which belong to 
those classes, though.


If I read a big String into my application, it won't be counted 
towards the retained size of the web application classloader -- or 
will it? I don't understand how that String object could count towards 
the classloader's memory footprint.


It should do. The profiler traces obejct references and they should all 
lead back to the web application class loader.


What reference path would lead from a java.lang.String object to the web 
application ClassLoader? It's allocation-path? That would be tied to the 
Thread which allocated it, not to the TCCL the Thread happened to have 
at the time.


I've never tried to do this before and I suspect you have, so I'm not 
trying to say "you're wrong" -- because I know better ;) -- but I'd like 
to understand what exactly I'm missing, here.


-chris

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Per context heap usage

2022-05-17 Thread Mark Thomas

On 17/05/2022 17:34, Christopher Schultz wrote:

Mark,

On 5/17/22 08:17, Mark Thomas wrote:

On 17/05/2022 10:41, Thomas Meyer wrote:

Hi,

Is it possible to find out the per deployed context heap usage in 
tomcat?


With a profiler you can look at the retained size of the web 
application class loader instance associated with a web application.


I don't think this will tell you the volume of objects which belong to 
those classes, though.


If I read a big String into my application, it won't be counted towards 
the retained size of the web application classloader -- or will it? I 
don't understand how that String object could count towards the 
classloader's memory footprint.


It should do. The profiler traces obejct references and they should all 
lead back to the web application class loader.


Mark

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Per context heap usage

2022-05-17 Thread Christopher Schultz

Mark,

On 5/17/22 08:17, Mark Thomas wrote:

On 17/05/2022 10:41, Thomas Meyer wrote:

Hi,

Is it possible to find out the per deployed context heap usage in tomcat?


With a profiler you can look at the retained size of the web application 
class loader instance associated with a web application.


I don't think this will tell you the volume of objects which belong to 
those classes, though.


If I read a big String into my application, it won't be counted towards 
the retained size of the web application classloader -- or will it? I 
don't understand how that String object could count towards the 
classloader's memory footprint.


-chris

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Per context heap usage

2022-05-17 Thread Mark Thomas

On 17/05/2022 10:41, Thomas Meyer wrote:

Hi,

Is it possible to find out the per deployed context heap usage in tomcat?


With a profiler you can look at the retained size of the web application 
class loader instance associated with a web application.


Mark

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Per context heap usage

2022-05-17 Thread Thomas Meyer
Hi,

Is it possible to find out the per deployed context heap usage in tomcat?

Mfg
Thomas