THRIFT-926. cpp: Don't sleep in TFileTransport if we have data to write
authorDavid Reiss <dreiss@apache.org>
Wed, 6 Oct 2010 17:10:29 +0000 (17:10 +0000)
committerDavid Reiss <dreiss@apache.org>
Wed, 6 Oct 2010 17:10:29 +0000 (17:10 +0000)
commit0e0eb354527cecdc22d1c0e6ecba06d7f747e728
tree96002a775da4764d700e299d4bca379e678cf898
parenta0e11597163def6727896a77490899681c1eb6d6
THRIFT-926. cpp: Don't sleep in TFileTransport if we have data to write

Previously, the TFileTransport writer thread behaved as follows:

  while true:
    wait for main thread to notify new data in enqueueBuffer_
    swap(enqueueBuffer_, dequeueBuffer_)
    write out everything in dequeueBuffer_

Now the behavior is:

  while true:
    if enqueueBuffer_ is empty
      wait for main thread to notify new data in enqueueBuffer_
    swap(enqueueBuffer_, dequeueBuffer_)
    write out everything in dequeueBuffer_

The old behavior had a couple problems:
- Writes that arrived while the writer thread was writing
  dequeueBuffer_ wouldn't get processed immediately.  The writer thread
  would always wait until another write occurred after it started its
  condition variable wait, or until it timed out (3 seconds by default).

- If the main thread was writing fast enough to fill up enqueueBuffer_
  while the writer thread was still writing out dequeueBuffer_, it would
  block the next write call until the writer thread swapped the buffers.
  Unfortunately, the writer thread waits to do this until it the main
  thread notifies it of another write.  This deadlock is only broken by
  the 3 second timeout.  Performance then tanks, since the writer thread
  now always sleeps 3 seconds each time around the loop.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1005153 13f79535-47bb-0310-9956-ffa450edef68
lib/cpp/src/transport/TFileTransport.cpp