I'm trying to use HttpWebRequest and HttpWebResponse in .NET 3.5, running them in asynchronously: BeginGetRequestStream, EndGetRequestStream, BeginWrite, EndWrite, BeginGetResponse, EndGetResponse, BeginRead, EndRead - all parts of handling a request are asynchronous.
I have a few threads that send a large number of concurrent requests. EndRead and EndWrite are both blocking operations - they block the current thread while the actual read/write against the stream is done, I'm trying to come up with an ideal input/output buffer size for these operations.
My reasoning is this: as I have multiple requests active at a time, they'll keep firing callbacks to let the thread know there's some data available or data was sent. If my buffers are large, reading/writing the data through the wire will take longer, so EndRead/EndWrite will block longer. This would force the other requests on the same thread to wait a bit longer, since their notifications will have to wait until the thread is unblocked.
So, my question is, what would be a good read / write buffer size in this situation. I was thinking 2048 bytes each, but some sample code I saw in various blogs show wildly different values.
Thanks in advance for any ideas.