Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Threads

Threads

Scheduled Pinned Locked Moved C#
questionlounge
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ShimiG
    wrote on last edited by
    #1

    Im now starting to think of developing a big chat system which will need to handle up to 1000 clients connected at once. my question is how it would of be the best way to handle all of the 1000 clients?? a thread for each client isnt too much ?

    S U 2 Replies Last reply
    0
    • S ShimiG

      Im now starting to think of developing a big chat system which will need to handle up to 1000 clients connected at once. my question is how it would of be the best way to handle all of the 1000 clients?? a thread for each client isnt too much ?

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      You're right, creating a thread for each client won't scale. The best way to go about this is to use a threadpool. There is the System.Threading.ThreadPool[^] class provided by the .NET Framework. If you don't find it sufficient for your needs, there are also custom implementations of managed threadpools, a simple search in CP for "ThreadPool" should give you plenty of results. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      S 1 Reply Last reply
      0
      • S S Senthil Kumar

        You're right, creating a thread for each client won't scale. The best way to go about this is to use a threadpool. There is the System.Threading.ThreadPool[^] class provided by the .NET Framework. If you don't find it sufficient for your needs, there are also custom implementations of managed threadpools, a simple search in CP for "ThreadPool" should give you plenty of results. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        S Offline
        S Offline
        ShimiG
        wrote on last edited by
        #3

        Isnt thread pool can proccess only 25 threads at a time? (max) and 1000 active socket will create me a bottle neck

        S 1 Reply Last reply
        0
        • S ShimiG

          Isnt thread pool can proccess only 25 threads at a time? (max) and 1000 active socket will create me a bottle neck

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          That limit is per processor, so if you have a dual processor machine, then it's 50 threads. If you want more threads than that, then it defeats the very purpose of having the threadpool. The basic assumption behind using a threadpool is you can distribute the work among a few precreated threads, so you have never have one thread idle and another doing all the work. You can have a look here[^] if you want a custom implementation of Threadpools. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          S 1 Reply Last reply
          0
          • S S Senthil Kumar

            That limit is per processor, so if you have a dual processor machine, then it's 50 threads. If you want more threads than that, then it defeats the very purpose of having the threadpool. The basic assumption behind using a threadpool is you can distribute the work among a few precreated threads, so you have never have one thread idle and another doing all the work. You can have a look here[^] if you want a custom implementation of Threadpools. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

            S Offline
            S Offline
            ShimiG
            wrote on last edited by
            #5

            If i understand right threadpool are good for threads which dont do much work and alot of time under wait state isnt it the exact opposite of my problem? alot of active sockets ?

            S 1 Reply Last reply
            0
            • S ShimiG

              Im now starting to think of developing a big chat system which will need to handle up to 1000 clients connected at once. my question is how it would of be the best way to handle all of the 1000 clients?? a thread for each client isnt too much ?

              U Offline
              U Offline
              User 1798181
              wrote on last edited by
              #6

              I did something like this using remoting, delegates and events. It was pretty easy. I would avoid the mutithread, because it can become complex and it will slow you proformance with that many threads open.

              1 Reply Last reply
              0
              • S ShimiG

                If i understand right threadpool are good for threads which dont do much work and alot of time under wait state isnt it the exact opposite of my problem? alot of active sockets ?

                S Offline
                S Offline
                S Senthil Kumar
                wrote on last edited by
                #7

                Again, what you say is true for the system provided threadpool thread. I'm saying this for the umpteenth time, you can always find custom implementations of it on the web. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups