WCF NetTcpBinding Buffered vs Streamed performance problems

前端 未结 1 927
谎友^
谎友^ 2021-02-06 06:08

I wrote a WCF service that should transform any size of files, using the Streamed TransferMode in NetTcpBinding, and System.IO.Stream object.

W

1条回答
  •  深忆病人
    2021-02-06 06:13

    How big are the chunks you are streaming? You might experiment with varying chunk sizes, and varying strategies.
    Also, consider using Asynch IO to fill the buffers to be transferred, or after transfer.

    What I mean is, if your streaming algorithm is serial, like so:

    1. Fill a chunk
    2. send the chunk
    3. get confirmation
    4. more chunks?  Go to step 1
    

    ...then you have a lot of unnecessary delay. If you can fill chunks and send chunks in parallel, then you'll be able to reduce waiting. Async IO is one way to do that. You would have two parallel workstreams happening. Conceptually, it might look like this:

    Filling Chunks                              Sending Chunks
      1. call BeginRead                           1. get next chunk
      2. wait for callback                        2. send it
      3. more to read? yes -> go to step 1        3. await confirmation
      4. done                                     4. more? go to step 1
    

    But using Async IO, these could actually be driven by the same thread.

    Keep this in mind:

    Did you read MS's article on the topic of large data streaming in WCF?

    0 讨论(0)
提交回复
热议问题