Solved

Thread creation error : not enough storage.

Posted on 2003-11-27
13
6,072 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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
 

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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Create your own, high-performance VM backup appliance by installing NAKIVO Backup & Replication directly onto a Synology NAS!
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…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

690 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