The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: How to get a memory snapshot

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 7 - Last Post: Nov 11, 2008 12:49 PM by: claudio
Ryan de Laplante
How to get a memory snapshot
Posted: Nov 10, 2008 1:35 PM
  Click to reply to this thread Reply

I'm trying to use NetBeans to compare two heap dumps taken seconds apart
to help me find a memory leak. The heapdumps are of GlassFish with my
app running inside. I took them using VisualVM. VisualVM did not
detect the GlassFish running as a windows service, so I had to connect
to it using JMX. I think I lose a lot of VisualVM features when doing that.

Anyway, NetBeans doesn't seem to let me compare two heap dumps, it wants
Profiler Snapshots (.nps files). Any idea how I can do this with
GlassFish running as a Windows service? Maybe I need to stop the server
and start it from the command prompt so that Visual VM can attach to it.


Thanks,
Ryan


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Peter Williams
Re: How to get a memory snapshot
Posted: Nov 10, 2008 1:49 PM   in response to: Ryan de Laplante
  Click to reply to this thread Reply

Ryan de Laplante wrote:
> I'm trying to use NetBeans to compare two heap dumps taken seconds
> apart to help me find a memory leak. The heapdumps are of GlassFish
> with my app running inside. I took them using VisualVM.
> VisualVM did not detect the GlassFish running as a windows service, so
> I had to connect to it using JMX.
Odd. Are you running GlassFish on JDK 5 or JDK 6? You'll get better
results if running on JDK 6 as VisualVM will use the profiler api's
available in that version. IIRC, what you describe is what will happen
if you are running on JDK 5.
> I think I lose a lot of VisualVM features when doing that.
I don't think this is necessarily true. But see above, re: JDK 5.

-Peter
>
> Anyway, NetBeans doesn't seem to let me compare two heap dumps, it
> wants Profiler Snapshots (.nps files). Any idea how I can do this
> with GlassFish running as a Windows service? Maybe I need to stop the
> server and start it from the command prompt so that Visual VM can
> attach to it.
>
>
> Thanks,
> Ryan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Ryan de Laplante
Re: How to get a memory snapshot
Posted: Nov 10, 2008 2:27 PM   in response to: Peter Williams
  Click to reply to this thread Reply

I'm using JDK 6 update 7. When I run GlassFish as a Windows service,
the only way I can get VisualVM to connect to it is using JMX, and the
profiler tab is not visible.

If I shut down the windows service and start GlassFish from the command
prompt, VisualVM shows a GlassFish tree node and I can use the profiler
with it. If I connect to GlassFish using JMX, the profiler tab is
visible.

Anyway the profiler doesn't seem to be able to attach itself to a
running GlassFish instance. I let it try for about 20 minutes before
stopping it.

Do you know how to capture what NetBeans needs to do a compare of two
heap dumps? NetBeans is not on the production server. I want to use
some tool to capture the data.


Thanks,
Ryan



Peter Williams wrote:
> Ryan de Laplante wrote:
>> I'm trying to use NetBeans to compare two heap dumps taken seconds
>> apart to help me find a memory leak. The heapdumps are of GlassFish
>> with my app running inside. I took them using VisualVM. VisualVM
>> did not detect the GlassFish running as a windows service, so I had
>> to connect to it using JMX.
> Odd. Are you running GlassFish on JDK 5 or JDK 6? You'll get better
> results if running on JDK 6 as VisualVM will use the profiler api's
> available in that version. IIRC, what you describe is what will
> happen if you are running on JDK 5.
>> I think I lose a lot of VisualVM features when doing that.
> I don't think this is necessarily true. But see above, re: JDK 5.
>
> -Peter
>>
>> Anyway, NetBeans doesn't seem to let me compare two heap dumps, it
>> wants Profiler Snapshots (.nps files). Any idea how I can do this
>> with GlassFish running as a Windows service? Maybe I need to stop
>> the server and start it from the command prompt so that Visual VM can
>> attach to it.
>>
>>
>> Thanks,
>> Ryan
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Tim Quinn
Re: How to get a memory snapshot
Posted: Nov 10, 2008 2:41 PM   in response to: Ryan de Laplante
  Click to reply to this thread Reply

Hi, Ryan.

Have you tried using jmap to capture the heap dump(s) and then analyze
them? I'm not experienced in using NetBeans to compare two dumps but it
(at least the copy of 6.5 rc2 I have on my system) seems to be able to
load them. Because jmap should come with the Java runtime you should be
able to use it whether NB is on the same system as GlassFish or not.

Just a thought.

- Tim

Ryan de Laplante wrote:
> I'm using JDK 6 update 7. When I run GlassFish as a Windows service,
> the only way I can get VisualVM to connect to it is using JMX, and the
> profiler tab is not visible.
>
> If I shut down the windows service and start GlassFish from the
> command prompt, VisualVM shows a GlassFish tree node and I can use the
> profiler with it. If I connect to GlassFish using JMX, the profiler
> tab is visible.
> Anyway the profiler doesn't seem to be able to attach itself to a
> running GlassFish instance. I let it try for about 20 minutes before
> stopping it.
> Do you know how to capture what NetBeans needs to do a compare of two
> heap dumps? NetBeans is not on the production server. I want to use
> some tool to capture the data.
>
>
> Thanks,
> Ryan
>
>
>
> Peter Williams wrote:
>> Ryan de Laplante wrote:
>>> I'm trying to use NetBeans to compare two heap dumps taken seconds
>>> apart to help me find a memory leak. The heapdumps are of
>>> GlassFish with my app running inside. I took them using
>>> VisualVM. VisualVM did not detect the GlassFish running as a
>>> windows service, so I had to connect to it using JMX.
>> Odd. Are you running GlassFish on JDK 5 or JDK 6? You'll get better
>> results if running on JDK 6 as VisualVM will use the profiler api's
>> available in that version. IIRC, what you describe is what will
>> happen if you are running on JDK 5.
>>> I think I lose a lot of VisualVM features when doing that.
>> I don't think this is necessarily true. But see above, re: JDK 5.
>>
>> -Peter
>>>
>>> Anyway, NetBeans doesn't seem to let me compare two heap dumps, it
>>> wants Profiler Snapshots (.nps files). Any idea how I can do this
>>> with GlassFish running as a Windows service? Maybe I need to stop
>>> the server and start it from the command prompt so that Visual VM
>>> can attach to it.
>>>
>>>
>>> Thanks,
>>> Ryan
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Ryan de Laplante
Re: How to get a memory snapshot
Posted: Nov 10, 2008 3:16 PM   in response to: Tim Quinn
  Click to reply to this thread Reply

Earlier I used jmap to create my heap dumps and NetBeans Heap Analyzer
to dig through them... but I find it quite useless since it is 300 MB
and I don't see any obvious sign of my program having a leak. I want to
diff two heap dumps. I know NetBeans and VisualVM have a feature to
compare snapshots, but it won't take two heap dumps. I will ask the
NetBeans users mailing list how to do this, or look in the docs first.

Thanks,
Ryan


Tim Quinn wrote:
> Hi, Ryan.
>
> Have you tried using jmap to capture the heap dump(s) and then analyze
> them? I'm not experienced in using NetBeans to compare two dumps but
> it (at least the copy of 6.5 rc2 I have on my system) seems to be able
> to load them. Because jmap should come with the Java runtime you
> should be able to use it whether NB is on the same system as GlassFish
> or not.
>
> Just a thought.
>
> - Tim
>
> Ryan de Laplante wrote:
>> I'm using JDK 6 update 7. When I run GlassFish as a Windows
>> service, the only way I can get VisualVM to connect to it is using
>> JMX, and the profiler tab is not visible.
>>
>> If I shut down the windows service and start GlassFish from the
>> command prompt, VisualVM shows a GlassFish tree node and I can use
>> the profiler with it. If I connect to GlassFish using JMX, the
>> profiler tab is visible.
>> Anyway the profiler doesn't seem to be able to attach itself to a
>> running GlassFish instance. I let it try for about 20 minutes
>> before stopping it. Do you know how to capture what NetBeans needs to
>> do a compare of two heap dumps? NetBeans is not on the production
>> server. I want to use some tool to capture the data.
>>
>>
>> Thanks,
>> Ryan
>>
>>
>>
>> Peter Williams wrote:
>>> Ryan de Laplante wrote:
>>>> I'm trying to use NetBeans to compare two heap dumps taken seconds
>>>> apart to help me find a memory leak. The heapdumps are of
>>>> GlassFish with my app running inside. I took them using
>>>> VisualVM. VisualVM did not detect the GlassFish running as a
>>>> windows service, so I had to connect to it using JMX.
>>> Odd. Are you running GlassFish on JDK 5 or JDK 6? You'll get
>>> better results if running on JDK 6 as VisualVM will use the profiler
>>> api's available in that version. IIRC, what you describe is what
>>> will happen if you are running on JDK 5.
>>>> I think I lose a lot of VisualVM features when doing that.
>>> I don't think this is necessarily true. But see above, re: JDK 5.
>>>
>>> -Peter
>>>>
>>>> Anyway, NetBeans doesn't seem to let me compare two heap dumps, it
>>>> wants Profiler Snapshots (.nps files). Any idea how I can do this
>>>> with GlassFish running as a Windows service? Maybe I need to stop
>>>> the server and start it from the command prompt so that Visual VM
>>>> can attach to it.
>>>>
>>>>
>>>> Thanks,
>>>> Ryan
>>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Peter Williams
Re: How to get a memory snapshot
Posted: Nov 10, 2008 3:06 PM   in response to: Ryan de Laplante
  Click to reply to this thread Reply

I have to echo what Tim said -- I haven't used VisualVM much for this --
I use JMap + JHat + an external stack processing tool I wrote a few
years ago that strips out all the redundant data.

As for the Service vs. console -- Are you running on Vista? Is the
service running as a different user or with different privileges than
you are? My guess is that the OS is not allowing VisualVM access to the
process space.

Regardless, JMX should offer almost the same set of data -- I think the
profiling data will be missing, so if that is what you wanted, there you go.

-Peter

Ryan de Laplante wrote:
> I'm using JDK 6 update 7. When I run GlassFish as a Windows service,
> the only way I can get VisualVM to connect to it is using JMX, and the
> profiler tab is not visible.
>
> If I shut down the windows service and start GlassFish from the
> command prompt, VisualVM shows a GlassFish tree node and I can use the
> profiler with it. If I connect to GlassFish using JMX, the profiler
> tab is visible.
> Anyway the profiler doesn't seem to be able to attach itself to a
> running GlassFish instance. I let it try for about 20 minutes before
> stopping it.
> Do you know how to capture what NetBeans needs to do a compare of two
> heap dumps? NetBeans is not on the production server. I want to use
> some tool to capture the data.
>
>
> Thanks,
> Ryan
>
>
>
> Peter Williams wrote:
>> Ryan de Laplante wrote:
>>> I'm trying to use NetBeans to compare two heap dumps taken seconds
>>> apart to help me find a memory leak. The heapdumps are of
>>> GlassFish with my app running inside. I took them using
>>> VisualVM. VisualVM did not detect the GlassFish running as a
>>> windows service, so I had to connect to it using JMX.
>> Odd. Are you running GlassFish on JDK 5 or JDK 6? You'll get better
>> results if running on JDK 6 as VisualVM will use the profiler api's
>> available in that version. IIRC, what you describe is what will
>> happen if you are running on JDK 5.
>>> I think I lose a lot of VisualVM features when doing that.
>> I don't think this is necessarily true. But see above, re: JDK 5.
>>
>> -Peter
>>>
>>> Anyway, NetBeans doesn't seem to let me compare two heap dumps, it
>>> wants Profiler Snapshots (.nps files). Any idea how I can do this
>>> with GlassFish running as a Windows service? Maybe I need to stop
>>> the server and start it from the command prompt so that Visual VM
>>> can attach to it.
>>>
>>>
>>> Thanks,
>>> Ryan
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


jsedlacek

Posts: 2
Re: How to get a memory snapshot
Posted: Nov 11, 2008 11:27 AM   in response to: Ryan de Laplante
  Click to reply to this thread Reply

VisualVM uses various technologies to access the monitored applications: jvmstat, JMX, Attach API etc. Based on the monitored application setup some of the technologies may not be available - for example Attach API is only available on JDK 6, jvmstat can only be used to access applications launched by the same user.

The reason why you don't see Profiler tab and some other features are disabled for the Glassfish service is that it doesn't run in context of the user. You can check it by the jps command - if it doesn't list the Glassfish process, VisualVM doesn't know about it. If you connect to the server using the JMX, only the metrics/operations published by MBeans are available, which doesn't cover profiling (which requires Attach API).

Afaik the only way to profile Glassfish using VisualVM is to start the server manually as a Java process (asadmin start-domain...). But note that neither the NetBeans profiler nor VisualVM will let you compare two heap dumps. Currently only comparing two (profiler) memory snapshots taken with the same settings is supported.

Anyway, based on what information is available in the heap dump only number of instances and their sizes could be compared, which is exactly what you get (and even more) when you compare two memory snapshots taken by the profiler. Another possibility to hunt for the leak is simply profile memory and reset the results before invoking the action/operation which could potentially leak - this way you will only see the newly created objects and - if enabled - their allocation stack traces.

Hope this helps,
Jiri

claudio

Posts: 58
Re: How to get a memory snapshot
Posted: Nov 11, 2008 12:49 PM   in response to: Ryan de Laplante
  Click to reply to this thread Reply

You can use Eclipse Memory Analyser, there is a "compare dumps" feature.

http://eclipse.org/mat




 XML java.net RSS