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
1 file changed