Solved

Thread creation error : not enough storage.

Posted on 2003-11-27
13
5,817 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

760 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

24 Experts available now in Live!

Get 1:1 Help Now