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