I think it's the BeginWrite that's causing the problem. Each
BeginWrites runs on its own threadpool thread, so there is no guarantee
they would be executed in the same order in which they were fired.
OTOH, I don't think blocking further EndRecieve's till the BeginWrite
completes is a good solution. I'd suggest creating a separate thread
waiting over a single queue, that synchronously writes out items posted
in the queue to the disk.
This way, the socket handling code would simply post a message to the
queue and continue receiving other messages, while your thread writes
the posted messages in the correct order.
Hope this helps.
Regards
Senthil
Lee Gillie - 16 Aug 2005 06:23 GMT
> I think it's the BeginWrite that's causing the problem. Each
> BeginWrites runs on its own threadpool thread, so there is no guarantee
[quoted text clipped - 13 lines]
> Regards
> Senthil
I like your strategy. I am guessing I can get most of my potential
throughput capacity back in this way. I'll try it tomorrow.
I eventually figured out that in my receive handler, it was interrupted
by another receive completion before the disk write was queued. I feel
pretty certain that writes are made in the order they are queued. I have
stacked them up before in other work and preserved data order. But it is
vital to protect the code between end receive and begin write so that
interruption does not occur, otherwise the writes are not queued in the
correct order. I don't know if I can start a synclock before the end
receive call though. It occurs to me that interruption could occur by
the very next line of code. Although I never actually found this to
happen, there is not much code between my original end-receive and
begin-write call.
Your strategy allows me to always effectively queue the write on almost
the very next line of code after the end-write. Reducing the
interruption effect. I think the early queuing of the next begin-receive
opens the opportunity for interruption.
It is not clear to me how we are supposed to protect servicing of
end-receive from interruption 100% and without throttling back the
throughput. If an end-receive is interrupted by another thread of
end-receive it seems likely the one doing the interruption will complete
before the first one.
- Lee