Thread Limits

C

Cablito

1º. Is there a limit for threads on Windows?

I have created a test program in vb.net and it seems as if after 160 threads
it stalls and does not create new threads. WTF?

Natural question I expect is "why in gods name do you want to create
hundreds of threads?"

I might be wrong and it might not be needed, just makes sense to me that I
need them. I want to make a SMTP proxy, I want to listen at port 25 internet
address and relay to another server, inside the lan. Well, the load I need
to handle is somewhere around 300 simultaneous users, 24 hours a day. Made
sense to me that each "client" had a thread.

Anyone?
 
I

Imran Koradia

I'm not sure of the exact limit number but yes, I believe there is a limit
on the number of threads you can spawn off from a single process. To
implement a scalable server, you should instead use the ThreadPool class.
Here's an article:

http://www.codeproject.com/dotnet/dotnettcp.asp

hope that helps..
Imran.
 
W

Willy Denoyette [MVP]

Threads are expensive resources in Windows use them sparingly, each thread
has it's own stack space (1MB VM per default) which limits the number of
threads that can be mapped on a 2GB users memory space to about 1200-1500.
But this is a ridiculous high number which will only result in a CPU
starvation because of the extreme number of context switches, unless there
are only a few runable threads, in which case it's a waste of memory
resources.

However, to build scalable servers, you shouldn't care about threads, all
you need to apply a asynchronous programming model using the
BeginXXX/EndXXXX methods of the Socket class (or NetworkStream class).
Check the MSDN doc's for BeginAccespt/EndAccept, EndRead/BeginRead etc in
the Socket and NetworkStream class for some samples.
Also check "Using an Asynchronous Client Socket" and in general "Using
Asynchronous IO" in .NET.

Willy.
 
W

Willy Denoyette [MVP]

There is no exact limit, all depends how much free user VM memory space
there is, and whether you are running with 3GB switch turned on.
But 1500 seems like a reasonable figure.

Willy.
 
G

Guest

Hi,

Using an Asynchronous Socket is good idea but not perfect solution.I
implemented such kind of application using thread pool and asynchronous
server socket but it's not so scalable eventhough we have quite strong
hardaware.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top