You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stephen Caine <st...@commongrnd.com> on 2008/04/03 16:49:48 UTC

Threads

List members:

I have a process that generates hundreds of threads.  Running on Mac  
OS X 10.5.2 Server, the thread count tops out at approximately 2500.   
After which, the process is terminated.  The heap size is set to 1  
gigabyte.  My question is how to increase the capacity of the JVM to  
handle more threads.  Is the value of 2500 an absolute limit, or can  
it be modified by setting the thread allocation, increasing heap size  
or the use of another java option?

As an aside, this issue did not occur with Mac OS X 10.4 Server.

If you have time, what causes a process to generate threads?

Any advice will be appreciated.

Stephen Caine
Soft Breeze Systems, LLC

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Threads

Posted by Stephen Caine <st...@commongrnd.com>.
Yong,
>
> Add to here:
> export JAVA_OPTS="-d64 -Xms1024m -Xmx1024m -XX:+MaxFDLimit -server - 
> Djava.awt.headless=false"

Thank you.

Stephen

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Threads

Posted by Yong Hyeon Yoon <yo...@inprinciple.org>.
On 3-Apr-08, at 11:27 AM, Stephen Caine wrote:
> Yong,
>
>> Are you running on 32-bit or 64-bit JVM on OS X 10.5.2?
>> If you are running java without -d64, it would be running 32-bit by  
>> default.
>>
>> Typicaly around 2000 or so is the thread number limit on 32-bit  
>> process due to its virtual address space limit (1 thread may claim  
>> 1MB of virtual space for stack). Running java with -d64 will invoke  
>> 64-bit JVM on leopard, and should increase the threads limit  
>> accordingly.  The actual physical heap space is different story. It  
>> needs to increase only if you app/thread really use/allocate memory.
>>
>> But I am wondering why Tiger server did not have the issue. AFAIK,  
>> 64-bit JVM is only available on Leopard.
>
>
> This is the exact route I was thinking.  We have an XServe running  
> 10.5, so I want to run in 64 bit mode.  I think I am currently in 32  
> bit mode as I have not set any special flag to change the default.   
> I have found the magic flag, -d64, but I do not know where to set  
> this.  We are using a start up script as follows:
>
> #!/bin/sh
> export CATALINA_HOME=$2
> export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
> export JAVA_OPTS="-Xms1024m -Xmx1024m -XX:+MaxFDLimit -server - 
> Djava.awt.headless=false"
> cd "$CATALINA_HOME"
> cd bin
> ./startup.sh
>
> Where (and how) is the 64 bit flag set?
>

Add to here:
export JAVA_OPTS="-d64 -Xms1024m -Xmx1024m -XX:+MaxFDLimit -server - 
Djava.awt.headless=false"

Yong






> Thank you for your assistance.
>
> Stephen Caine
> Soft Breeze Systems, LLC
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Threads

Posted by Stephen Caine <st...@commongrnd.com>.
Yong,

> Are you running on 32-bit or 64-bit JVM on OS X 10.5.2?
> If you are running java without -d64, it would be running 32-bit by  
> default.
>
> Typicaly around 2000 or so is the thread number limit on 32-bit  
> process due to its virtual address space limit (1 thread may claim  
> 1MB of virtual space for stack). Running java with -d64 will invoke  
> 64-bit JVM on leopard, and should increase the threads limit  
> accordingly.  The actual physical heap space is different story. It  
> needs to increase only if you app/thread really use/allocate memory.
>
> But I am wondering why Tiger server did not have the issue. AFAIK,  
> 64-bit JVM is only available on Leopard.


This is the exact route I was thinking.  We have an XServe running  
10.5, so I want to run in 64 bit mode.  I think I am currently in 32  
bit mode as I have not set any special flag to change the default.  I  
have found the magic flag, -d64, but I do not know where to set this.   
We are using a start up script as follows:

#!/bin/sh
export CATALINA_HOME=$2
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
export JAVA_OPTS="-Xms1024m -Xmx1024m -XX:+MaxFDLimit -server - 
Djava.awt.headless=false"
cd "$CATALINA_HOME"
cd bin
./startup.sh

Where (and how) is the 64 bit flag set?

Thank you for your assistance.

Stephen Caine
Soft Breeze Systems, LLC

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Threads

Posted by Yong Hyeon Yoon <yo...@inprinciple.org>.
Are you running on 32-bit or 64-bit JVM on OS X 10.5.2?
If you are running java without -d64, it would be running 32-bit by  
default.

Typicaly around 2000 or so is the thread number limit on 32-bit  
process due to its virtual address space limit (1 thread may claim 1MB  
of virtual space for stack). Running java with -d64 will invoke 64-bit  
JVM on leopard, and should increase the threads limit accordingly.
The actual physical heap space is different story. It needs to  
increase only if you app/thread really use/allocate memory.

But I am wondering why Tiger server did not have the issue. AFAIK, 64- 
bit JVM is only available on Leopard.

Yong


On 3-Apr-08, at 7:49 AM, Stephen Caine wrote:
> List members:
>
> I have a process that generates hundreds of threads.  Running on Mac  
> OS X 10.5.2 Server, the thread count tops out at approximately  
> 2500.  After which, the process is terminated.  The heap size is set  
> to 1 gigabyte.  My question is how to increase the capacity of the  
> JVM to handle more threads.  Is the value of 2500 an absolute limit,  
> or can it be modified by setting the thread allocation, increasing  
> heap size or the use of another java option?
>
> As an aside, this issue did not occur with Mac OS X 10.4 Server.
>
> If you have time, what causes a process to generate threads?
>
> Any advice will be appreciated.
>
> Stephen Caine
> Soft Breeze Systems, LLC
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Threads

Posted by Stephen Caine <st...@commongrnd.com>.
Chuck,
>
> There are some thread-specific parameters you can play with, in  
> particular -Xss.  But as others have pointed out, changing one  
> factor moves the limits on others.  Your best bet (assuming you  
> really, really need that many threads) is to run in a 64-bit  
> process, also as previously suggested.

I posted a response and hopefully I will get some good advice.
>
>> increasing the size of the heap (from 1 to 1 gigs).
>
> That's not much of an increase...

True enough.  I meant to say, 1 to 2 gigs (but I bet you knew that).

Stephen

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Threads

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Stephen Caine [mailto:stephen@commongrnd.com] 
> Subject: Re: Threads
> 
> I am asking if there is any way to increase the number of 
> threads that can be handled by decreasing the thread size
> allocation (a java option)

There are some thread-specific parameters you can play with, in
particular -Xss.  But as others have pointed out, changing one factor
moves the limits on others.  Your best bet (assuming you really, really
need that many threads) is to run in a 64-bit process, also as
previously suggested.

> increasing the size of the heap (from 1 to 1 gigs).

That's not much of an increase...

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Threads

Posted by Stephen Caine <st...@commongrnd.com>.
Chuck,
>
> There's no limit within the JVM itself on the number of threads,  
> other than heap space required to hold the Thread objects.  It's the  
> underlying OS that imposes the actual limit, including the amount of  
> process space available for stacks and other thread-specific  
> structures.  If you're not getting an OOME, it's an OS limit that's  
> killing the process.

Thank you for the explanation.

I am asking if there is any way to increase the number of threads that  
can be handled by decreasing the thread size allocation (a java  
option) and/or increasing the size of the heap (from 1 to 1 gigs).

Thanks,

Stephen Caine
Soft Breeze Systems, LLC

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Threads

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Stephen Caine [mailto:stephen@commongrnd.com] 
> Subject: Threads
> 
> My question is how to increase the capacity of the JVM to  
> handle more threads.

There's no limit within the JVM itself on the number of threads, other
than heap space required to hold the Thread objects.  It's the
underlying OS that imposes the actual limit, including the amount of
process space available for stacks and other thread-specific structures.
If you're not getting an OOME, it's an OS limit that's killing the
process.

> If you have time, what causes a process to generate threads?

This kind of Java code:
   new Thread().run()
(or variations thereof).

What are you really asking for here?

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] Threads

Posted by Andrew Miehs <an...@2sheds.de>.
On 03/04/2008, at 7:14 PM, Christopher Schultz wrote:
>
> Alan Chaney wrote:
> | Actually another question is what is it in your application that  
> NEEDS
> | 2500 threads?
>
> Ooh! I know... it's a ray-tracer that goes reeeeal fast if you give  
> each
> output pixel its own thread. More threads = faster, right? Hoo-ray for
> threads!
>

Doh! and I thought he had 2500 processors!...

Silly me.

Andrew

Re: [OT] Threads

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alan,

Alan Chaney wrote:
| Actually another question is what is it in your application that NEEDS
| 2500 threads?

Ooh! I know... it's a ray-tracer that goes reeeeal fast if you give each
output pixel its own thread. More threads = faster, right? Hoo-ray for
threads!

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkf1EHkACgkQ9CaO5/Lv0PC+6gCgrfa7qUR+MGSHpqGvboABSI0g
IREAoLhkjH/YalcVmuRkhOeTjQeVHWw8
=C3d1
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Threads

Posted by Alan Chaney <al...@compulsivecreative.com>.
Actually another question is what is it in your application that NEEDS 
2500 threads? What does the application do? Is it 3rd party or in house?

Normally the creation of a thread is considered an expensive operation 
and typically one tries to avoid creating new threads all over the 
place. Hence thread pools as used by tomcat.



Peter Crowther wrote:
>> From: Stephen Caine [mailto:stephen@commongrnd.com]
>> I have a process that generates hundreds of threads.  Running on Mac
>> OS X 10.5.2 Server, the thread count tops out at approximately 2500.
>> After which, the process is terminated.  The heap size is set to 1
>> gigabyte.  My question is how to increase the capacity of the JVM to
>> handle more threads.  Is the value of 2500 an absolute limit, or can
>> it be modified by setting the thread allocation, increasing heap size
>> or the use of another java option?
> 
> I'm not a Mac person, but... does the Mac JVM use native threads?  In which case, the 2500 (plus other threads) could be an OS limit that has changed in 10.5.
> 
>> If you have time, what causes a process to generate threads?
> 
> Calls to the API that generates a thread.  Next?
> 
>                 - Peter
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 
> !DSPAM:47f507bc127041839419991!
> 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Threads

Posted by Andrew Miehs <an...@2sheds.de>.
>> From: Stephen Caine [mailto:stephen@commongrnd.com]
>> I have a process that generates hundreds of threads.  Running on Mac
>> OS X 10.5.2 Server, the thread count tops out at approximately 2500.
>> After which, the process is terminated.  The heap size is set to 1
>> gigabyte.  My question is how to increase the capacity of the JVM to
>> handle more threads.  Is the value of 2500 an absolute limit, or can
>> it be modified by setting the thread allocation, increasing heap size
>> or the use of another java option?
>

What error message are you seeing in catalina.out?

You are probably running out of memory. Each thread needs a certain  
amount of heap and stack.
You may also want to look at the limits you set in the shell

Defaults from mac os x 10.5.2

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) 6144
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 266
virtual memory          (kbytes, -v) unlimited
$



RE: Threads

Posted by "Harper, Brad" <br...@epsiia.com>.
We recently resolved a similar problem on a win32 platform which
presented as a java.lang.OutOfMememoryError when attempting to create a
new native thread.

Native threads were being created [each with their own 1Mb stack in the
non-JVM heap space] in association with Thread objects as they were
being managed in the JVM.

In a paradox, increasing the heap available to the JVM can actually
cause a thread-greedy app to fail by limiting the memory available to
native threads.

It's possible to change the default native thread stack size on that
platform, but we didn't go down that route. It turned out to be "thread
leak"; unnecessary threads were being created and the GC wasn't
reclaiming their space [and therefore the native thread stack space].

Brad Harper
EPSIIA Inc.

> -----Original Message-----
> From: Peter Crowther [mailto:Peter.Crowther@melandra.com] 
> Sent: Thursday, April 03, 2008 11:34 AM
> To: 'Tomcat Users List'
> Subject: RE: Threads
> 
> > From: Stephen Caine [mailto:stephen@commongrnd.com] I have 
> a process 
> > that generates hundreds of threads.  Running on Mac OS X 10.5.2 
> > Server, the thread count tops out at approximately 2500.
> > After which, the process is terminated.  The heap size is set to 1 
> > gigabyte.  My question is how to increase the capacity of 
> the JVM to 
> > handle more threads.  Is the value of 2500 an absolute 
> limit, or can 
> > it be modified by setting the thread allocation, increasing 
> heap size 
> > or the use of another java option?
> 
> I'm not a Mac person, but... does the Mac JVM use native 
> threads?  In which case, the 2500 (plus other threads) could 
> be an OS limit that has changed in 10.5.
> 
> > If you have time, what causes a process to generate threads?
> 
> Calls to the API that generates a thread.  Next?
> 
>                 - Peter
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org To 
> unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Threads

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Stephen Caine [mailto:stephen@commongrnd.com]
> I have a process that generates hundreds of threads.  Running on Mac
> OS X 10.5.2 Server, the thread count tops out at approximately 2500.
> After which, the process is terminated.  The heap size is set to 1
> gigabyte.  My question is how to increase the capacity of the JVM to
> handle more threads.  Is the value of 2500 an absolute limit, or can
> it be modified by setting the thread allocation, increasing heap size
> or the use of another java option?

I'm not a Mac person, but... does the Mac JVM use native threads?  In which case, the 2500 (plus other threads) could be an OS limit that has changed in 10.5.

> If you have time, what causes a process to generate threads?

Calls to the API that generates a thread.  Next?

                - Peter

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org