Thread Limits

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cablito

    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?


  • Imran Koradia

    #2
    Re: Thread Limits

    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:



    hope that helps..
    Imran.

    "Cablito" <cablito@dontsp am.com> wrote in message
    news:OiLI$SkqEH A.348@TK2MSFTNG P15.phx.gbl...[color=blue]
    > 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[/color]
    threads[color=blue]
    > 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[/color]
    internet[color=blue]
    > 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?
    >
    >[/color]


    Comment

    • Willy Denoyette [MVP]

      #3
      Re: Thread Limits

      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" <cablito@dontsp am.com> wrote in message
      news:OiLI$SkqEH A.348@TK2MSFTNG P15.phx.gbl...[color=blue]
      > 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?
      >
      >[/color]


      Comment

      • Sriram Krishnan

        #4
        Re: Thread Limits

        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




        "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message
        news:uXze56kqEH A.556@tk2msftng p13.phx.gbl...[color=blue]
        > 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" <cablito@dontsp am.com> wrote in message
        > news:OiLI$SkqEH A.348@TK2MSFTNG P15.phx.gbl...[color=green]
        >> 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?
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Thread Limits

          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" <ksriram@NOSPAM gmx.net> wrote in message
          news:eIAj4qErEH A.3896@TK2MSFTN GP15.phx.gbl...[color=blue]
          >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]" <willy.denoyett e@pandora.be> wrote in message
          > news:uXze56kqEH A.556@tk2msftng p13.phx.gbl...[color=green]
          >> 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" <cablito@dontsp am.com> wrote in message
          >> news:OiLI$SkqEH A.348@TK2MSFTNG P15.phx.gbl...[color=darkred]
          >>> 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?
          >>>
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Onder Ozcan

            #6
            Re: Thread Limits

            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:
            [color=blue]
            > 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" <cablito@dontsp am.com> wrote in message
            > news:OiLI$SkqEH A.348@TK2MSFTNG P15.phx.gbl...[color=green]
            > > 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?
            > >
            > >[/color]
            >
            >
            >[/color]

            Comment

            Working...