473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Thread Limits

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?
Jul 21 '05 #1
5 2163
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.

"Cablito" <ca*****@dontspam.com> wrote in message
news:Oi*************@TK2MSFTNGP15.phx.gbl...
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?

Jul 21 '05 #2
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.

"Cablito" <ca*****@dontspam.com> wrote in message
news:Oi*************@TK2MSFTNGP15.phx.gbl...
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?

Jul 21 '05 #3
I remember putting writing a toy app which kept on spawning threads to find
this limit. I hit around 1500 everytime (forgot the exact number) and then
CreateThread wouldnt return

--
Sriram Krishnan

http://www.dotnetjunkies.com/weblog/sriram
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uX*************@tk2msftngp13.phx.gbl...
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.

"Cablito" <ca*****@dontspam.com> wrote in message
news:Oi*************@TK2MSFTNGP15.phx.gbl...
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?


Jul 21 '05 #4
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.

"Sriram Krishnan" <ks*****@NOSPAMgmx.net> wrote in message
news:eI**************@TK2MSFTNGP15.phx.gbl...
I remember putting writing a toy app which kept on spawning threads to find
this limit. I hit around 1500 everytime (forgot the exact number) and then
CreateThread wouldnt return

--
Sriram Krishnan

http://www.dotnetjunkies.com/weblog/sriram
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uX*************@tk2msftngp13.phx.gbl...
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.

"Cablito" <ca*****@dontspam.com> wrote in message
news:Oi*************@TK2MSFTNGP15.phx.gbl...
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?



Jul 21 '05 #5
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.


"Willy Denoyette [MVP]" wrote:
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.

"Cablito" <ca*****@dontspam.com> wrote in message
news:Oi*************@TK2MSFTNGP15.phx.gbl...
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?


Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin | last post by:
Hi, I am continualy receiving the following type of error in my browser from programs using php/mysql Warning: mysql_connect(): Can't create a new thread (errno 11). If you are not out of...
6
by: ll | last post by:
Hi, How to specify the timeout value(ms) for a thread? Thanks.
5
by: Alvin Bruney | last post by:
I dispensed some advice and its bugging me that it may not be 100% accurate. Worker threads should not touch main thread objects. Everybody knows that but if you pass a reference to a form object...
16
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
6
by: Cablito | last post by:
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...
3
by: archana | last post by:
Hi all, i want to develop one windows service wherein i want to run task continuously after certain interval. So what i did is i created one thread and in that thread i have written one...
3
by: Jake Weller | last post by:
Hi everyone, Is it safe to call a GUI control's members directly from another thread. That is, if I launch a background thread when the user clicks a button on my form, can I safely retrieve...
13
by: Josip | last post by:
I'm trying to limit a value stored by object (either int or float): class Limited(object): def __init__(self, value, min, max): self.min, self.max = min, max self.n = value def...
23
by: =?GB2312?B?0rvK18qr?= | last post by:
Hi all, Recently I had a new coworker. There is some dispute between us. The last company he worked for has a special networking programming model. They split the business logic into...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.