Thread creation error : not enough storage.

hi folks,

I have an NT-service which contains a Tserversocket which opens a thread for each connection..

Problem: When reaching somewhere inbetween 1700 and 2000 threads, I get this error "Thread creation error: Not enough storage is available to process this command" and everything halts in the service ;-(

And yes I KNOW that there is plenty of RAM (4Gigabyte) and PLENTY disk space (24*80GB).

Is there some kind of setting I can set either in Delphi on compiler time, or in Windows ??

its run on a 4 cpu computer its coded in Delphi 7 and run under Windows 2000 advanced server btw.

Thanks guys.
GOMFAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GOMFAuthor Commented:
Gosh maybe I should start writting "W indows 2000" instead of Windows 2000 - cooomerrcial break ;-)

just a lamo comment.
0
sftwengCommented:
Have you played with image and stack sizes? Go to Project -> Options -> Linker -> Memory Sizes and fiddle with the image base and min and max stack sizes? The Min Stack size might give you the best benefit, provided you don't run into stack overflow.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jcondeCommented:
Maybe this will help you sort the problem out:

http://support.microsoft.com/default.aspx?kbid=819989
0
Lee_NoverCommented:
as sftweng suggested it's a problem with StackSize
default stacksize for delphi apps is 1mb
every TThread gets the same stack size as the main thread - 1mb
a process can get 2GB of virtual mem - max < 2000 threads (1 mb/per thread) per process
threads stack size is set on threads creation and can't be changed with the current VCL implementation
you could create your own thread class and 'hack' arround the stack size problem

and some info from MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/thread_stack_size.asp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robert_marquardtCommented:
I doubt that Windows is very efficient with that many threads.
Try to create a thread pool.
0
GOMFAuthor Commented:

Gosh I love this EE thingy!

Great answers folks! I am looking at them all.

Lee_Nover : Think I can override this behaviour in my TThread implementation somehow? I will try that. I can't see this behaviour as it appears that each thread uses around 50kb mem - based on what the taskmanager tells me , I can't see that it uses 1mb/thread. Is stack usage not "accounted for" ?

Robert: Actually it is quite efficient and its the only way that is technically acceptable to do what we want to do.

sftweng: Yes I thought about it, but I am a bit "affraid" it might hurt my main (the service controller interface and thread starter + socket listener) as it might run out of stack (crash).

shivsa: I dont think this is the same problem.

I am not even sure that this problem will ever occur when we roll out, but if I can resolve I should; it will only occur if 1900+ clients at the same time will attempt to open a connection. We have a base of max. 3000 users, but my subsystem is called only in specific actions (writting data to the SQL).

Thanks a bunch guys, I will return in a bit!


Regards,

GOMF
0
GOMFAuthor Commented:
Just remember i missed a comment

jconde: i have asked maintanence to install this if its not installed. This COM object; do you know what it is? I am not instantiating this on purpose.

Regards,
GOMF
0
sftwengCommented:
To protect the main thread, set a high maximum stack value but to get a large number of the other threads, set a low min value.
0
Lee_NoverCommented:
you could create your own constructor that doesn't call TThread's inherited Create
I'd 'hack' the vcl code ;)
add a default parameter StackSize: Integer = 0 to the construcotr
create(Suspended: Boolean; StackSize: Integer = 0)

ofcourse copy the classes unit to the project folder to modify it .. and add it to the projects file list
0
sftwengCommented:
Have you considered switching the TServerSocket to nonblocking and using the events to handle I/O? You'd use less memory and fewer cycles with that many threads.
0
Lee_NoverCommented:
tnx

so .. what have you done ? :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Storage Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.