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 / C++ / MFC
  4. IOCP server

IOCP server

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelpquestion
10 Posts 4 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.
  • J Offline
    J Offline
    Jhony george
    wrote on last edited by
    #1

    Hai, i am working with IOCP server and normal socket Client. i have created 2 threads in my server side(in a thread pool). and trying to connect more number of clients using threads. But Only 3969 clients are getting connected at a time.... as of use in IOCP we can connect 65000 clients .....but atleast i want 10,000 clients to connect. What is the issue over here... reply me, Mani

    Born to win...!

    C M M 3 Replies Last reply
    0
    • J Jhony george

      Hai, i am working with IOCP server and normal socket Client. i have created 2 threads in my server side(in a thread pool). and trying to connect more number of clients using threads. But Only 3969 clients are getting connected at a time.... as of use in IOCP we can connect 65000 clients .....but atleast i want 10,000 clients to connect. What is the issue over here... reply me, Mani

      Born to win...!

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      How many threads are created in total ?

      D.Mani wrote:

      and trying to connect more number of clients using threads.

      Do you have one thread that gets created for each clients that connect ?


      Cédric Moonen Software developer
      Charting control [v1.2]

      J 1 Reply Last reply
      0
      • C Cedric Moonen

        How many threads are created in total ?

        D.Mani wrote:

        and trying to connect more number of clients using threads.

        Do you have one thread that gets created for each clients that connect ?


        Cédric Moonen Software developer
        Charting control [v1.2]

        J Offline
        J Offline
        Jhony george
        wrote on last edited by
        #3

        hai, thanks for reply, here is my code : 1.for (int ii = 0; ii < nNoOfThreads; ii++) 2.{ 3.b = CreateConnectedSocket(&(pThreadInfo[ii].m_Socket),"192.168.60.206", nPortNo); 4.if(b) 5.{ 6. pThreadInfo[ii].m_nThreadNo = ii+1; 7. p_hThreads[ii] = CreateThread(NULL, 4096, WorkerThread,(void *)(&pThreadInfo[ii]), STACK_SIZE_PARAM_IS_A_RESERVATION, &nThreadID); 8.} in for loop "nNoOfThreads= 4500", and the 3rd line i am creating socket, and trying to connect with passed parameters. now..each 4500 sockets has o create, den create thread will take care of message send and receving... now the issue is only 3969 sockets are created... and the 3969 threads are created. Mani.

        Born to win...!

        C 1 Reply Last reply
        0
        • J Jhony george

          hai, thanks for reply, here is my code : 1.for (int ii = 0; ii < nNoOfThreads; ii++) 2.{ 3.b = CreateConnectedSocket(&(pThreadInfo[ii].m_Socket),"192.168.60.206", nPortNo); 4.if(b) 5.{ 6. pThreadInfo[ii].m_nThreadNo = ii+1; 7. p_hThreads[ii] = CreateThread(NULL, 4096, WorkerThread,(void *)(&pThreadInfo[ii]), STACK_SIZE_PARAM_IS_A_RESERVATION, &nThreadID); 8.} in for loop "nNoOfThreads= 4500", and the 3rd line i am creating socket, and trying to connect with passed parameters. now..each 4500 sockets has o create, den create thread will take care of message send and receving... now the issue is only 3969 sockets are created... and the 3969 threads are created. Mani.

          Born to win...!

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Do you know what a thread is ? Do you understand that you need some resources to manage one single thread ? Do you also understand that switching between different threads take some time, so imagine what will happen if you have to switch between 10000 threads. Multithreading is achieved by time slicing: your processor will work on one thread for a small amount of time, then switch to another thread for another small amount of time and so on... So, guess what happens when you have 10000 threads ? Nothing works anymore because there are just too much threads to be handled.

          D.Mani wrote:

          What is the issue over here...

          You are just asking too much from the system. There not enough memory to manage all the threads that you are creating. This should ring a bell that your design is just plain wrong. Some people already told you that creating so many thread is a bad idea. Now you see the reason.


          Cédric Moonen Software developer
          Charting control [v1.2]

          J 1 Reply Last reply
          0
          • C Cedric Moonen

            Do you know what a thread is ? Do you understand that you need some resources to manage one single thread ? Do you also understand that switching between different threads take some time, so imagine what will happen if you have to switch between 10000 threads. Multithreading is achieved by time slicing: your processor will work on one thread for a small amount of time, then switch to another thread for another small amount of time and so on... So, guess what happens when you have 10000 threads ? Nothing works anymore because there are just too much threads to be handled.

            D.Mani wrote:

            What is the issue over here...

            You are just asking too much from the system. There not enough memory to manage all the threads that you are creating. This should ring a bell that your design is just plain wrong. Some people already told you that creating so many thread is a bad idea. Now you see the reason.


            Cédric Moonen Software developer
            Charting control [v1.2]

            J Offline
            J Offline
            Jhony george
            wrote on last edited by
            #5

            hai, i want to check whther my server is stable and able to serve more number clients...approximately 10,000 clients... all of them are trying to access this server at a time... So, i need to give simultanoues access to the server..so i decided to use threads....for creating that many connections at a time.... each and every thread will start connecting to the server.., i am not goin this way...without any aim...please understand this....

            Born to win...!

            M 1 Reply Last reply
            0
            • J Jhony george

              Hai, i am working with IOCP server and normal socket Client. i have created 2 threads in my server side(in a thread pool). and trying to connect more number of clients using threads. But Only 3969 clients are getting connected at a time.... as of use in IOCP we can connect 65000 clients .....but atleast i want 10,000 clients to connect. What is the issue over here... reply me, Mani

              Born to win...!

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              This is the third time I've answered this. The IOCP is so you don't have to create a thread for every connection. You can try, but it's not going to happen.  1000 connection threads takes over a GB of RAM by default, all of which will spend 99.999999% of the time doing nothing. Did you read the articles at the links I provided twice before? Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              • J Jhony george

                hai, i want to check whther my server is stable and able to serve more number clients...approximately 10,000 clients... all of them are trying to access this server at a time... So, i need to give simultanoues access to the server..so i decided to use threads....for creating that many connections at a time.... each and every thread will start connecting to the server.., i am not goin this way...without any aim...please understand this....

                Born to win...!

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                No, really you ARE going without aim.  With an IOCP, you can service 10s of thousands of connections with just a few threads. If you think every connection needs a thread, or that it's even possible for 10,000 threads to simultaneously run on a machine with less than 10,000 CPUs, then you really don't understand threads at all. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                M 1 Reply Last reply
                0
                • J Jhony george

                  Hai, i am working with IOCP server and normal socket Client. i have created 2 threads in my server side(in a thread pool). and trying to connect more number of clients using threads. But Only 3969 clients are getting connected at a time.... as of use in IOCP we can connect 65000 clients .....but atleast i want 10,000 clients to connect. What is the issue over here... reply me, Mani

                  Born to win...!

                  M Offline
                  M Offline
                  Mike Dimmick
                  wrote on last edited by
                  #8

                  When using I/O completion ports you are supposed to have a much smaller pool of threads. The operating system only runs as many threads concurrently as are necessary to keep the CPUs busy. I haven't got space here to explain it fully, you should see "Programming Server-Side Applications for Windows" for more information, but basically when a thread calls GetQueuedCompletionStatus, it will block. When an I/O request completes, and the number of threads already running is less than the number of CPUs, Windows will unblock the first waiting thread. Threads that complete their request and call GetQueuedCompletionStatus again go back to the head of the queue (this should keep the thread's data variables 'hot' in the processor cache). The magic is this: if a thread that is associated with a completion port blocks for some other reason, Windows looks to see if there are now fewer threads than the number of CPUs running, and if so, it releases another one. On the whole, this keeps the number of threads down and therefore the number of context switches between runnable threads minimized (which is time spent unnecessarily switching between threads that could otherwise have been used for useful work). Each new thread requires its own stack. The actual stack size reserved depends on compiler switches, by default, 1MB per thread. Multiplying up you can see that 3,969 threads is about 4GB of reserve. You're blowing your entire virtual address space on thread stacks. That's the practical limit of how many threads you can create in one process.


                  DoEvents: Generating unexpected recursion since 1991

                  1 Reply Last reply
                  0
                  • M Mark Salsbery

                    No, really you ARE going without aim.  With an IOCP, you can service 10s of thousands of connections with just a few threads. If you think every connection needs a thread, or that it's even possible for 10,000 threads to simultaneously run on a machine with less than 10,000 CPUs, then you really don't understand threads at all. Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    M Offline
                    M Offline
                    Mike Dimmick
                    wrote on last edited by
                    #9

                    I think he's actually trying to emulate clients using a single thread per client. However, he's running into the same problem - you can't create huge numbers of threads in a single process because you run out of virtual memory. I think he's falling foul of the fact that even though he's only asking for a 4KB stack reserve, he's actually getting 64KB as that's the minimum that Windows VirtualAlloc will reserve. He's therefore blowing 256MB of virtual address space on thread stacks out of the 2GB available, presumably the rest being allocated by some other data structures and by the amount of code loaded into the process. This is assuming that he's not actually blowing some other system data structure (handle table?) first. Large-scale testing of servers is pretty tricky without actually getting thousands of people together each operating their own client. Right now my thin-client application server only has a Windows port of the client which can be automated, so I have one process per client (and it's a console-mode process, so one window per client). The practical limit is about 600 clients per test box, which is consuming about 70% of a 2 x Xeon 5150 box's CPU power due to a few odd timing loops and all the overhead of console mode output being RPCs to the CSRSS process which actually draws the windows.


                    DoEvents: Generating unexpected recursion since 1991

                    M 1 Reply Last reply
                    0
                    • M Mike Dimmick

                      I think he's actually trying to emulate clients using a single thread per client. However, he's running into the same problem - you can't create huge numbers of threads in a single process because you run out of virtual memory. I think he's falling foul of the fact that even though he's only asking for a 4KB stack reserve, he's actually getting 64KB as that's the minimum that Windows VirtualAlloc will reserve. He's therefore blowing 256MB of virtual address space on thread stacks out of the 2GB available, presumably the rest being allocated by some other data structures and by the amount of code loaded into the process. This is assuming that he's not actually blowing some other system data structure (handle table?) first. Large-scale testing of servers is pretty tricky without actually getting thousands of people together each operating their own client. Right now my thin-client application server only has a Windows port of the client which can be automated, so I have one process per client (and it's a console-mode process, so one window per client). The practical limit is about 600 clients per test box, which is consuming about 70% of a 2 x Xeon 5150 box's CPU power due to a few odd timing loops and all the overhead of console mode output being RPCs to the CSRSS process which actually draws the windows.


                      DoEvents: Generating unexpected recursion since 1991

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      Mike Dimmick wrote:

                      Large-scale testing of servers is pretty tricky without actually getting thousands of people together each operating their own client.

                      Definitely.  Even then, it's hard to push the server software very far since the network (and any other device I/O, like a DB on a harddisk) will probably be the first bottleneck.

                      Mike Dimmick wrote:

                      I think he's actually trying to emulate clients using a single thread per client.

                      Clients.  My bad :)  Still, the same principles apply and it's been discussed repeatedly. Great replies, BTW, thanks! Cheers, Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      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