• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Confusion on Garbage Collection and Memory Consumption

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

First of all pardon my english if you cant understand it that well. Ill try my best.

We are currently load testing an application deployed on Websphere 5 running on Win2k3 OS. When we view the javaw.exe memory consumption in the task manager, it says it consumes 630MB. When we examine the garbage collection data, majority of the memory usage before garbage collection was 512MB then goes down to 130MB after garbage collection. If that is the case, why does javaw.exe in the task manager show the memory consumption playing around 630-645MB? Should it be going down to 130MB and up again to 512MB if that is what is shown in the garbage collection data?

2nd question is, after the load testing, we are expecting the memory to go down and stabilize to a lower value. How come it stays at 630MB even after our load test? shouldn't it be lowered because of garbage collection? Quite odd since based on garbage collection data, we can still see memory being freed up although no longer that often. Does the windows task manager really show it that way or does that say there is a memory leak in our app?

Our websphere settings:
Initial heap size: 512MB
Max Heap size: 1.5GB
Server machine: 3GB RAM

Thanks. I would appreciate any help or advise.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The behavior that you observed is completely normal.

First, when Java obtains memory from the OS, it never releases it back, even if the objects in the heap are released. It just holds on to the memory and recycles it for the next object being allocated on the heap. This is done because obtaining memory from the OS is expensive. So, Java holds on to the memory and reuses it

Second, GC is a very lazy operation. GC will not collect objects until it absolutely has to, or an internal timer triggers it. This is because GC is costly, and GC benifits from economy of scale. The more objects to collect, the faster it is to collect individual objects. So, the expected behavior on an application that is mostly idle is that heap usage grows till an internal timer triggers and cleans the heap. If the application is active and using lot of memory, GC will be triggered when heap usage hits max. If you watch memory usage on a tool like JConsole, you will see a graph that looks like a saw. This is completely normal.

What you want to look for is the bottom of the saw stays straight (or atleast goes down once processing is complete). That's your "real" memory usage
 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jayesh A Lalwani wrote:The behavior that you observed is completely normal.

First, when Java obtains memory from the OS, it never releases it back, even if the objects in the heap are released. It just holds on to the memory and recycles it for the next object being allocated on the heap. This is done because obtaining memory from the OS is expensive. So, Java holds on to the memory and reuses it

Second, GC is a very lazy operation. GC will not collect objects until it absolutely has to, or an internal timer triggers it. This is because GC is costly, and GC benifits from economy of scale. The more objects to collect, the faster it is to collect individual objects. So, the expected behavior on an application that is mostly idle is that heap usage grows till an internal timer triggers and cleans the heap. If the application is active and using lot of memory, GC will be triggered when heap usage hits max. If you watch memory usage on a tool like JConsole, you will see a graph that looks like a saw. This is completely normal.

What you want to look for is the bottom of the saw stays straight (or atleast goes down once processing is complete). That's your "real" memory usage



Thanks Jayesh. Learned something new there.

So....when my applications reached a memory consumption equal or slightly greater than whatever was set in the initial heap size (-Xms) of my JVM, thats the only time GC would run? Is that how it really works? If yes then whats the point of setting the maximum heap size (-Xmx)?

and when we take a look at the windows task manager....whatever memory size we see the javaw.exe consuming is the memory allocated to the JVM? and not the total memory every java application consumes in real time? Am I correct?

 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andres Delrotti wrote:

Thanks Jayesh. Learned something new there.

So....when my applications reached a memory consumption equal or slightly greater than whatever was set in the initial heap size (-Xms) of my JVM, thats the only time GC would run? Is that how it really works? If yes then whats the point of setting the maximum heap size (-Xmx)?


-Xms controls how much memory the Java process will obtain from the OS as soon as it starts(no matter what the avtual heap usage). -Xmx controls the maximum memory Java will obtain from OS

When the app is idle, GC will run periodically, no matter what the usage. WHen the app is busy, GC will run when heap usage hits -Xmx



and when we take a look at the windows task manager....whatever memory size we see the javaw.exe consuming is the memory allocated to the JVM? and not the total memory every java application consumes in real time? Am I correct?



Yes. For checking the size of the heap, you have to use tools that come with JDK.. like JConsole, or take a heap dump. You cannot rely on the OS to report the size of the heap correctly.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic