Steven Erat's Blog
 
 
Viewing By Entry
 
 

TalkingTree  java.lang.OutOfMemoryError: unable to create new native thread

 

In tests that were done a couple years ago with ColdFusion MX, it was found that there is an upper limit on the number of operating system threads that can be open by one process, not to be confused with the number of file handle descriptors or jvm threads. When that os thread limit is reached for ColdFusion jrun process, the java.lang.OutOfMemoryError: unable to create new native thread error is thrown.

The results from testing on the Linux platform with Red Hat 7.x demonstrated the error when approximately 400 OS threads were tied to one OS process, the jvm process. Current Linux versions are thought to have improved that somewhat, so the limit might be higher at this time.

Solaris also demonstrated a limit, but had a higher threshold of about 1000-2000 OS threads per process, and Windows showed a limit of about 3000. at that time.

Given that for the JVM process under ColdFusion/JRun there is at least one operating system thread open for every JVM web thread, plus other operating system threads that are not tied to a JVM web thread, it is very likely that this error will occur if the total number of web threads (queued + running) begin to approach that experimental threshold of about 400 on Linux, for example.   Slow pages that might act as application bottlenecks can cause sufficient queuing where that OS thread limit would be reached, provided the maxHandlerThreads value in jrun.xml exceeds the experimental OS thread threshold. The default for maxHandlerThreads is 1000, so on Linux a maxHandlerThreads size of 500 or greater would likely see this error if the queue size ballooned.

Similarly, setting the activeHandlerThreads size to an unusually high number might also cause the error when sufficient numbers of users are on the application even if queueing is not occuring. Recently I have seen one such server where activeHandlerThreads (Simultanous Requests) was set to 500 and the "unable to create new native thread error" was the prominent symptom.

In those hypothetical configurations, the error java.lang.OutOfMemoryError: unable to create new native thread would begin to saturate the JRun logs. To clarify the error text, the error message means that no more native, or OS, threads can be created for the JVM process, causing the JVM to throw an exception. The exception type is java.lang.outOfMemoryError, but I find that to be rather misleading since the resource limitation on the OS thread count, not memory usage.

In the end, if so many web threads are being created that you're running into this error, then you'd probably want to hunt down bottlenecks via thread dumps and logging slow pages in order to increase throughput to get a lean mean activeHandler pool and reduce queuing. But if queuing is a problem, then you're more likely to see the "unable to create new native thread" error on Linux than on Solaris, and least likely to see this on Windows, although poor throughput looks the same no matter what the platform.

Related Blogs:

 


Comments

The reason for this is the stack size. On Linux, each thread gets its own stack with a default size of 512kB. On my machine, there is only 3 GB for the stacks, so in theory I can only create 6144 threads. But there is more that needs memory, therefore I can only create about 5700 threads. If I increase to 1MB of stack, I can create about 2700 threads and when I reduce it to 128kb, I can create much more.

You can have a look at the process with "pmap" to see the memory allocated by the threads. Generally speaking, if you need more than the mentioned 400 threads, try to reduce the stack size using "-Xss128k" which should give you about 4 times the threads. Most applications should work fine with this stack size. If not, you'll get a "StackOverflowError" and have to increase the stack. I found a lower limit mentioned of 96kb on Linux.

Kurt Huwig


Great information! Thanks Kurt


Am I the only one who is thoroughly confused by the whole J2EE / memory situation? Half the posts I read say increase the memory to 1MB, and the other half say reduce it to 128k. I would assume, that an app that is throwing "out of memory" errors needs MORE memory, no?

This is incredibly frustrating, if you don't mind my saying!

Cheers,

David


 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Search This Site

 
This is an exact search only

About This Site

 
I live west of Boston and used to work at Adobe with ColdFusion and Flex, specializing in Unix & Linux. I recently graduated from CDIA in Pro Digital Photography. Curious about my banner image?

More about me

Recent Entries

 
Christmas Eve Service makes F..
How To Filter by File Type in..
Perspective on ColdFusion's B..
Power Mac G5: The lights are ..
My Application to CDIABU in R..

Recent Comments

 
Posted By Andy Allan:
Fantastic work Steve.

Posted By charlie arehart:
Oh wow, awesome to hear that the relative quiet was an imposed one, and that the gag order has been lifted. Now I'm really excited to hear what may co ...

Posted By Steven Erat:
Thanks for your encouragement Charlie. I have to say that even though I'm trying to be positive and use this time to improve my web skills, most of t ...

recently played

 
Snap Judgments
by WNYC, New York Public Radio
on On The Media
On The Media, WNYC, New York Public Radio

now playing, a plug-in for itunes

Categories

 
RSS Adobe (31)
RSS Bicycling (9)
RSS Blogging (37)
RSS Books (13)
RSS Breeze (12)
RSS CFMX Podcasts (10)
RSS ColdFusion (420)
RSS Computer Technology (50)
RSS Events (25)
RSS Flash (3)
RSS Flex (18)
RSS Gadgets (10)
RSS HiTech Industry (16)
RSS Java (25)
RSS Learning (57)
RSS Linux (70)
RSS Mac OS X (22)
RSS Macromedia (28)
RSS Meetup (34)
RSS New England (62)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (29)
RSS Photography (109)
RSS Photoshop (29)
RSS Podcasts (18)
RSS Rants (19)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

Blogs I Read

 
Scrum Sucks
Ben Forta
Ray Camden
Kinky Solutions
Gary Gilbert
Red Hat Blogs
O'Reilly Digital Media
O'Reilly Radar
John Nack
The Strobist
Scott Kelby
Matt Kloskowski
Joe McNally
Digital Photography School
Engadget
Science Blog

RSS

 


Add to Google
Add to My Yahoo!

Aggregated By

 


Consumed By Feed-Squirrel.com
Aggregated by ColdFusionBlogger.org

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software
CJM Group - ColdFusion Website Hosting


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2009 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer