Solved

Thread creation error : not enough storage.

Posted on 2003-11-27
13
5,855 Views
Last Modified: 2013-11-15
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.
0
Comment
Question by:GOMF
  • 4
  • 3
  • 3
  • +3
13 Comments
 

Author Comment

by:GOMF
ID: 9833732
Gosh maybe I should start writting "W indows 2000" instead of Windows 2000 - cooomerrcial break ;-)

just a lamo comment.
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9833746
0
 
LVL 7

Expert Comment

by:sftweng
ID: 9834778
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
 
LVL 7

Expert Comment

by:jconde
ID: 9835045
Maybe this will help you sort the problem out:

http://support.microsoft.com/default.aspx?kbid=819989
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 500 total points
ID: 9835453
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
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 9835753
I doubt that Windows is very efficient with that many threads.
Try to create a thread pool.
0
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 

Author Comment

by:GOMF
ID: 9836030

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
 

Author Comment

by:GOMF
ID: 9836055
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
 
LVL 7

Expert Comment

by:sftweng
ID: 9836089
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
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 9836151
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
 
LVL 7

Expert Comment

by:sftweng
ID: 9969511
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
 
LVL 7

Expert Comment

by:sftweng
ID: 9969521
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12513416
tnx

so .. what have you done ? :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now