?
Solved

Thread creation error : not enough storage.

Posted on 2003-11-27
13
Medium Priority
?
6,167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 2000 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
 

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 12

Expert Comment

by:Lee_Nover
ID: 12513416
tnx

so .. what have you done ? :)
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…
Suggested Courses

752 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