views:

213

answers:

7

Hi,

I am trying to reproduce java.lang.OutOfMemoryException in Jboss4, which one of our client got, presumably by running the J2EE applications over days/weeks.

I am trying to find a way for the webapp to spitout java.lang.OutOfMemoryException in a matter of minutes (instead of days/weeks).

One thing come into mind is to write a selenium script and has the script bombards the webapps. One other thing that we can do is to reduce JVM heap size, but we would prefer not to do this, as we want to see the limit of our system.

Any suggestions?

ps: I don't have access to the source code, as we just provide a hosting service (of course I could decompile the class files...)

A: 

Do both, but in a controlled fashion :

  1. Reduce the available memory to the absolute minimum (using -Xms1M -Xmx2M, as an example, but I fear your app won't even load with such limitations)
  2. Do controlled "nuclear irradiation" : do Selenium scripts or each of the known working urls before to attack the presumed guilty one.
  3. Finally, unleash the power that shall not be raised : start VisualVM and any other monitoring software you can think of (DB execution is a usual suspect).
Riduidel
+1  A: 

If you don't have access to the source code of the J2EE app in question, the options that come to mind are:

  1. Reduce the amount of RAM available to the JVM. You've already identified this one and said you don't want to do it.

  2. Create a J2EE app (it could probably just be a JSP) and configure it to run within the same JVM as the target app, and have that app allocate a ridiculous amount of memory. That will reduce the amount of memory available to the target app, hopefully such that it fails in the way you're trying to force.

T.J. Crowder
hm i will try doing point 2, creating another J2EE app
portoalet
@ T.J, will option 2 cause the same OOM as what would be happening on the client side? You're just as likely to choke the app by reducing the heap size to throw OOM. Not necessarily the root cause of memory leak as the client is experiencing.
JoseK
@josek: His exception is happening server-side, not client-side. The goal of suggestion #2 is to use up a lot of memory so that when the target app is trying to get some, it throws the exception they're seeing after weeks of use. I assume they want to be able to make it happen intentionally for diagnostic purposes.
T.J. Crowder
@T.J: By client-side I meant on his client's JBoss instance, not "browser-side". Incorrect wording on my part.
JoseK
A: 

The root of the problem is most likely a memory leak in the webapp that the client is running. In order to track it down, you need to run the app with a representative workload with memory profiling enabled. Take some snapshots, and then use the profiler to compare the snapshots to see where objects are leaking. While source-code would be ideal, you should be able to at least figure out where the leaking objects are being allocated. Then you need to track down the cause.

However, if your customer won't release binaries so that you can run an identical system to what he is running, you are kind of stuck, and you'll need to get the customer to do the profiling and leak detection himself.

BTW - there is not a lot of point causing the webapp to throw an OutOfMemoryError. It won't tell you why it is happening, and without understanding "why" you cannot do much about it.

EDIT

There is not point "measuring the limits", if the root cause of the memory leak is in the client's code. Assuming that you are providing a servlet hosting service, the best thing to do is to provide the client with instructions on how to debug memory leaks ... and step out of the way. And if they have a support contract that requires you to (in effect) debug their code, they ought to provide you with the source code to do your job.

Stephen C
No I don't have access to the source code ( I can of course decompile the class files) as we operate just like a hosting provider.
portoalet
@portoalet - like I said, you don't need source-code access. Just access to the binaries / configs / etc to allow you to reproduce the client's webapp.
Stephen C
A: 

If you are using Sun Java 6, you may want to consider attaching to the application with jvisualvm in the JDK. This will allow you to do in-place profiling without needing to alter anything in your scenario, and may possibly immediately reveal the culprit.

Thorbjørn Ravn Andersen
sadly it is running on jre1.4.04
portoalet
+1  A: 

Try to use some profiling tools to investigate memory leakage. Also good to investigate memory damps that was taken after OOM happens and logs. IMHO: reducing memory is not the rightest way to investigate cose you can get issues not connected with real production one.

Artic
A: 

If you don't have the source use decompile it, at least if you think the terms of usage allows this and you live in a free country. You can use: Java Decompiler or JAD.

Rickard von Essen
A: 

In addition to all the others I must say that even if you can reproduce an OutOfMemory error, and find out where it occurred, you probably haven't found out anything worth knowing.

The trouble is that an OOM occurs when an allocation can not take place. The real problem however is not that allocation, but the fact that other allocations, in other parts of the code, have not been de-allocated (de-referenced and garbage collected). The failed allocation here might have nothing to do with the source of the trouble (no pun intended).

This problem is larger in your case as it might take weeks before trouble starts, suggesting either a sparsely used application, or an abnormal code path, or a relatively HUGE amount of memory in relation to what would be necessary if the code was OK.

It might be a good idea to ask around why this amount of memory is configured for JBoss and not something different. If it's recommended by the supplier than maybe they already know about the leak and require this to mitigate the effects of the bug.

For these kind of errors it really pays to have some idea in which code path the problem occurs so you can do targeted tests. And test with a profiler so you can see during run-time which objects (Lists, Maps and such) are growing without shrinking.

That would give you a chance to decompile the correct classes and see what's wrong with them. (Closing or cleaning in a try block and not a finally block perhaps).

In any case, good luck. I think I'd prefer to find a needle in a haystack. When you find the needle you at least know you have found it:)

extraneon