Mladen,

Thanks for the response. I'm sorry if my original post wasn't clear. I'll try 
to clarify.

The question is not "how to tell the Tomcat service what size stack to use." 
That, as you point out, can be set using the manager GUI, or parameters at 
service install time (both of which set registry entries which procrun/tomcat 
uses at run-time). Rather, the question is about what procrun/tomcat DOES with 
that data at run-time.

It is my observation that procrun/Tomcat does NOT honor the stack size that you 
set with the manager GUI. You can experiment with this by seeing how many 
threads you can create while running something in the context of Tomcat. I have 
a small JSP page that does this; I will append it at the end of this email. 
Edit the JSP page to set the number of threads to create. On a 32-bit Windows 
system, I can never create more than about 1200 threads. (I use 512 for min and 
max heap size; this number will affect how many threads you can get started as 
well, even though the stack space is not taken from the heap.) This would be 
consistent with each thread reserving a stack size of about 1 Mb. Specifying a 
different stack size with the manager GUI does NOT affect this behavior at all.

On Windows, the size of the stack for a native thread is taken from a field in 
the executable file header. You can use Microsoft's dumpbin and editbin 
utilities to examine and modify this value (or you can use a binary editor like 
WinHex). This field is set to 1 Mb in tomcat5.exe. If I modify the tomcat5.exe 
header to use 256 Kb instead of 1 Mb, then when I re-run my threads test I can 
get upwards of 5,000 threads started! (Interestingly, this works only if you do 
NOT specify a stack size in the manager GUI. If you specify a stack size, then 
I'm again limited to about 1200 threads.)

For more about stack size weirdness on Windows, please see:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/thread_stack_size.asp
 -- Microsoft article about thread stack sizes on Windows.

http://forum.java.sun.com/thread.jspa?threadID=580638&tstart=0 -- Sun forum 
entitled "Max threads when running under JNI". Basically a description of the 
same problem I'm seeing with Tomcat.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4689767 -- Sun Java bug 
report; the bug itself is not directly relevant, but some of Sun's comments are 
helpful. There appears to be some strange behavior around reserved vs committed 
stack space.

So, back to my original point: Given that a thread that's started when you run 
java.exe has a 256k stack on Windows, I think a thread that's started in the 
context of Tomcat should run with the same stack size. The way to do that 
appears to build tomcat5.exe with the reserve stack size set in the .exe header.

Does it make more sense now?

Thanks,
--Dan


----- threads.jsp -----
<%@ page import="java.io.*" %>

<p>
Starting...

<%

        MyThread.runTest( 1300 );
%>
<%!
        public static class MyThread extends Thread
        {
                public static void runTest( int nThreads ) throws 
InterruptedException
                {
                        MyThread threads[] = new MyThread[ nThreads ];
                        try
                        {
                                for ( int i = 0; i < nThreads; i++ )
                                {
                                        threads[ i ] = new MyThread( i );
                                }
                
                                System.out.println( "Starting " + nThreads + " 
threads..." );
                                for ( int i = 0; i < nThreads; i++ )
                                {
                                        threads[ i ].start();
                                }
                
                                System.out.println( "Running..." );
                                Thread.sleep( 5000 );
                        }
                        finally
                        {
                                for ( int i = 0; i < nThreads; i++ )
                                {
                                        threads[ i ].release();
                                }
                        }
                        
                        System.out.println( "Done." );
                }
                
                private int id;
        
                public MyThread( int childid )
                {
                        id = childid;
                }
        
                public synchronized void run()
                {
                        try
                        {
                                wait();
                        }
                        catch ( InterruptedException e )
                        {
                                e.printStackTrace();
                        }
                }
        
                public synchronized void release()
                {
                        notify();
                }
        }
%>

<p>
Done.
----------------------- 

-----Original Message-----
From: Mladen Turk [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 24, 2005 11:58 PM
To: Tomcat Developers List
Subject: Re: procrun and stack size

Daniel Rabe wrote:
> I'm running Tomcat 5.0.28 on Windows XP Pro. I recently discovered that the 
> number of threads I could create from within my webapp was significantly less 
> than I could running a program with java.exe. After a lot of research, I 
> discovered that if you run a JVM from a C wrapper (as Tomcat does with 
> procrun), the default stack size is taken from the "stack reserve" field in 
> the .exe header. Passing -Xss to the created JVM does not appear to have any 
> effect. Has anybody considered building Tomcat's procrun with a smaller stack 
> size, to make it more consistent with java.exe? In j2sdk 1.4.2_06 (I haven't 
> looked at other versions), java.exe is linked with a 256k stack. I would 
> suggest that would be a reasonable size for Tomcat as well.
>

I do not understand you question.
If it's how to set the stack size for the JVM, you can either use
manager gui or when install/update parameters use the
--JvmSs=NN that will be passed as -XssNNk

OTOH have no idea what would be the 'optimum' default stack size.
Also I'm not sure that java.exe itself sets the -Xss by itself unless
you explicitly pass that in command line.

Regards,
Mladen


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to