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. Question on Windows IOCP

Question on Windows IOCP

Scheduled Pinned Locked Moved C / C++ / MFC
questionjson
5 Posts 2 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
    SAMZCN
    wrote on last edited by
    #1

    As I know IOCP which is called one powerful model to meet socket program in scalable case, from then on I have a question on IOCP.Today, still puzzle me. The question is What will happen if you post more than one WSASend() request in one client socket which has been associated with the existing completion port. The scenario is as follows: IO Request:

    WSASend(...,wsaBuff1,1,...); // 1st send request for Buffer1 with 1MB data
    WSASend(...,wsaBuff2,1,...); // 2nd send request for Buffer2 with 1MB data
    WSASend(...,wsaBuff3,1,...); // 3rd send request for Buffer3 with 1MB data

    What will happen in the completion port? 1/ How many completion packet will be received? 2/ What is the order of the completion packet? 3/ Is it possbile to require more than one send request for each buffer? It means one time send request can't finish the data transmission. The user need to post another or more WSASend request for the rest data.

    M 1 Reply Last reply
    0
    • S SAMZCN

      As I know IOCP which is called one powerful model to meet socket program in scalable case, from then on I have a question on IOCP.Today, still puzzle me. The question is What will happen if you post more than one WSASend() request in one client socket which has been associated with the existing completion port. The scenario is as follows: IO Request:

      WSASend(...,wsaBuff1,1,...); // 1st send request for Buffer1 with 1MB data
      WSASend(...,wsaBuff2,1,...); // 2nd send request for Buffer2 with 1MB data
      WSASend(...,wsaBuff3,1,...); // 3rd send request for Buffer3 with 1MB data

      What will happen in the completion port? 1/ How many completion packet will be received? 2/ What is the order of the completion packet? 3/ Is it possbile to require more than one send request for each buffer? It means one time send request can't finish the data transmission. The user need to post another or more WSASend request for the rest data.

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

      SAMZCN wrote:

      How many completion packet will be received?

      One for each WSASend call. Always one for each completion packet queued.

      SAMZCN wrote:

      What is the order of the completion packet?

      If you only have one completion handler thread then they'll be in order queued. Multiple completion handler threads could execute in any order as always.

      SAMZCN wrote:

      Is it possbile to require more than one send request for each buffer?

      Yes it's possible, so you need to check if the entire buffer of data was sent for each call, same as always with sockets. Note: If you make multiple asynchronous WSASend calls using an I/O completion port then make sure all calls are made on the same thread. For TCP/IP, I personally much prefer only one outstanding read and/or one outstanding write per socket given the above information :)

      Mark Salsbery :java:

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        SAMZCN wrote:

        How many completion packet will be received?

        One for each WSASend call. Always one for each completion packet queued.

        SAMZCN wrote:

        What is the order of the completion packet?

        If you only have one completion handler thread then they'll be in order queued. Multiple completion handler threads could execute in any order as always.

        SAMZCN wrote:

        Is it possbile to require more than one send request for each buffer?

        Yes it's possible, so you need to check if the entire buffer of data was sent for each call, same as always with sockets. Note: If you make multiple asynchronous WSASend calls using an I/O completion port then make sure all calls are made on the same thread. For TCP/IP, I personally much prefer only one outstanding read and/or one outstanding write per socket given the above information :)

        Mark Salsbery :java:

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

        Hello Mark, Much appreciated for your input. I think it is very helpful to me.

        Mark Salsbery wrote:

        SAMZCN wrote:

        Is it possbile to require more than one send request for each buffer?

        Yes it's possible, so you need to check if the entire buffer of data was sent for each call, same as always with sockets.

        Note: If you make multiple asynchronous WSASend calls using an I/O completion port then make sure all calls are made on the same thread.

        For TCP/IP, I personally much prefer only one outstanding read and/or one outstanding write per socket given the above information :)

        At this point, it is the biggest puzzling thing to me. I read many articles on this issue about IOCP. But don't find any conclusion to make me convienced. By your saying, it seems really I need to check the whether the entire buffer in one request was sent out completely. If not, I need to post another send request for the rest data. Yes. Really I want to make multiple asynchronous WSASend calls using an I/O completion port to get performance improvement. But I can't make sure the calls are received by same thread. It is my problem. I do many trials on this. It seems meaningless. I agree that one outstanding IO operation per socket in a given time is a good way to get stable running. Thanks.:thumbsup:

        M 1 Reply Last reply
        0
        • S SAMZCN

          Hello Mark, Much appreciated for your input. I think it is very helpful to me.

          Mark Salsbery wrote:

          SAMZCN wrote:

          Is it possbile to require more than one send request for each buffer?

          Yes it's possible, so you need to check if the entire buffer of data was sent for each call, same as always with sockets.

          Note: If you make multiple asynchronous WSASend calls using an I/O completion port then make sure all calls are made on the same thread.

          For TCP/IP, I personally much prefer only one outstanding read and/or one outstanding write per socket given the above information :)

          At this point, it is the biggest puzzling thing to me. I read many articles on this issue about IOCP. But don't find any conclusion to make me convienced. By your saying, it seems really I need to check the whether the entire buffer in one request was sent out completely. If not, I need to post another send request for the rest data. Yes. Really I want to make multiple asynchronous WSASend calls using an I/O completion port to get performance improvement. But I can't make sure the calls are received by same thread. It is my problem. I do many trials on this. It seems meaningless. I agree that one outstanding IO operation per socket in a given time is a good way to get stable running. Thanks.:thumbsup:

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

          SAMZCN wrote:

          it seems really I need to check the whether the entire buffer in one request was sent out completely. If not, I need to post another send request for the rest data.

          With TCP/IP protocol, YES - always with sockets! (I say with TCP/IP since for example, UDP datagrams always go all at once).

          SAMZCN wrote:

          I want to make multiple asynchronous WSASend calls using an I/O completion port to get performance improvement. But I can't make sure the calls are received by same thread.

          Won't really be any performance increase.. The network stack (including the socket and the network adapter(s)) is a huge bottleneck and generally magnitudes slower than your running code. *edit* Plus you really can't since you need the result of the previous sends. Any thread synchronization you could maybe add to "solve" this would probably just slow down the IOCP since you'd have IOCP completion handler threads waiting on synch objects instead of waiting for completion packets so overall performance could suffer when many sockets are involved (which is where IOCPs really shine).

          Mark Salsbery :java:

          S 1 Reply Last reply
          0
          • M Mark Salsbery

            SAMZCN wrote:

            it seems really I need to check the whether the entire buffer in one request was sent out completely. If not, I need to post another send request for the rest data.

            With TCP/IP protocol, YES - always with sockets! (I say with TCP/IP since for example, UDP datagrams always go all at once).

            SAMZCN wrote:

            I want to make multiple asynchronous WSASend calls using an I/O completion port to get performance improvement. But I can't make sure the calls are received by same thread.

            Won't really be any performance increase.. The network stack (including the socket and the network adapter(s)) is a huge bottleneck and generally magnitudes slower than your running code. *edit* Plus you really can't since you need the result of the previous sends. Any thread synchronization you could maybe add to "solve" this would probably just slow down the IOCP since you'd have IOCP completion handler threads waiting on synch objects instead of waiting for completion packets so overall performance could suffer when many sockets are involved (which is where IOCPs really shine).

            Mark Salsbery :java:

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

            Hi Mark. Thanks. Appreciated for your share. It really helps me understand IOCP and other asnc IO operation.:thumbsup:

            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