Navigation

RSS 2.0 New Entries Syndication Feed Atom 0.3 New Entries Syndication Feed

Show blog menu v

 

General

Use it

Documentation

Support

Sibling projects

RIFE powered

Valid XHTML 1.0 Transitional

Valid CSS!

Blogs : Archives

avatar
< Announcing RIFE/Laszlo   Do nothing, successfully >
OutOfMemoryError with free memory

A few weeks ago I started getting OutOfMemoryError exceptions on a Linux production server. The free and top tools showed that there was still 1GB of free system memory. Also, after turning on verbose garbage collection statistics in the Java virtual machine, I saw that of the 700MB of heap, only 300MB was really used.

It took me days to track this down since I had no clue where to look at all. Finally it turned out that each Java thread reserves memory for the execution stack. On this system, the user's stack limit defaulted to 8MB (RHEL 2.1 AS). What I didn't know was that even though the thread didn't use the whole 8MB, the kernel still reserved the memory for each thread to be able to ensure that the memory could be used. However, since the memory was only reserved and not used, none of the statistics displayed that it wasn't available for anything else. Since Resin was configured with maximum 700 simulation threads, this could potentially result in the operating system reserving 5,5GM of memory (on a machine with only 3GB). So as soon as about 256 threads were created, shabaaang, any new thread would throw an OutOfMemoryError exception.

The solution was very simple, I simple added ulimit -s 1024 to the user's .bash_profile file. Now, the 700 threads only reserve 700MB and there's still plenty of room for other things.

Such a tiny setting makes a fundamental difference!

posted by Geert Bevin in Java on Jun 8, 2005 3:36 PM : 12 comments [permalink]
 

Comments

Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
Can you help me with that setting on Windows? have been using threads for a some time now, and cannot get around the prob for out of memory exceptions. TIA
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
I'm sorry, I never use Windows, so I have totally no idea how to configure this for it.
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
Which kernel version are you using?
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
Linux version 2.4.9-e.3smp (bhcompile@stripples.devel.redhat.com) (gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-108.1)) #1 SMP Fri May 3 16:48:54 EDT 2002

The standard RHEL 2.1 AS kernel, since it's a remote machine I don't dare to upgrade. I tried once by letting up2date install new rpms and the machine wasn't able to reboot afterwards :/

Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
I am curious, what about thread pooling? A site I am working on has to support up to 25 million users an hour, making mostly simple requests, but in many cases full on db transactions. Besides scaling veritcally with servers to handle the load (and presumably hardware to route the load fast enough), I was thinking a thread pool solution would offset a good portion of the problem. So, setting the thread memory size to like 2MB, creating a 1000 or so threads in a pool and using those to service requests, and provide more servers as needed, should do the trick… or no?
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
This is with thread pooling, a pool of maximum 700 threads.
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
700 threads! what the hell do you need that many for. it must be one hell of an app if it requires that many threads.
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
After some profiling I found that we only needed 400. In peek periods, we have 50 active threads with around 80 idle threads and 230 keepalive threads. So I set it at 400 to still have some headroom.
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
Uhm, I stumbled upon something very similar right today: could this happen on Solaris, too? I wonder if that stack size (1 meg) is enough for running an app server like websphere (which seems to have very deep call trees when functioning).
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
I'm sorry, I have no idea, we don't use Solaris.
Re: OutOfMemoryError with 1GB of free memory and 400MB of free heap
I think not, or at least not in the same way: counting the total number of threads we have in the system, and seen that the max stack size is 8M on my system too, we should have 3.7GB constantly filled with stacks (I mean in a normal, non problematic situation: and the machine has 4G8)! I imagine there must be some sort of correlation, but not exactly "8M per thread".
Re: OutOfMemoryError with free memory
Consider the ideas on this site
http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp

Add a new comment

:) ;)
=) :-)
:'( :(
:/ :D
:| :p
:o 8)
Your email address will not be displayed at anytime on any page.
Only provide your email address if you'd like updates on this entry
and it's comments by email.
Please answer this simple math question:
10 - 3 = 
 
 
  

Manage subscription

Remove email:
 

< Announcing RIFE/Laszlo   Do nothing, successfully >
 
 
 
Google
rifers.org web