Repository navigation
Cap the amount of buffering done by BytesPipe - #17877
Conversation
|
Looks super-cool. I'll review tomorrow. |
There was a problem hiding this comment.
as I see, bp.closed and bp.closeErr always changed together, so maybe we can eliminate closed and use just closeErr != nil instead?
3803892 to
42df0a4
Compare
|
LGTM |
|
@aaronlehmann There seems to be some kind of problem. The benchmark doesn't seem to finish right now. Can you look into this, please? update: I can confirm that the code is indeed deadlocking in the benchmarks: |
|
I wonder how that behchmark worked before :) It writes 500 1024 bytes chunk, but reading 1000 and it has check that n is 1024 each time. |
Turn BytesPipe's Read and Write functions into blocking, goroutine-safe functions. Add a CloseWithError function to propagate an error code to the Read function. Adjust tests to work with the blocking Read and Write functions. Remove BufReader, since now its users can use BytesPipe directly. Signed-off-by: Aaron Lehmann <[email protected]>
42df0a4 to
64f8ee4
Compare
|
Sorry about that - I missed the benchmarks. As @LK4D4 mentioned, the benchmark is trying to read more data than is written. With the new blocking behavior, this causes a deadlock (not that it would have worked before, either). I've fixed this by making the benchmark read one thousand 512 byte chunks instead. |
|
BTW, here is the change in benchmark results: before: after: I think the worse nubers in the "read" benchmark reflect the locking that was added. However, this doesn't reflect a real-world slowdown, because formerly |
|
The fact that it's slightly slower doesn't even matter. The whole point is to avoid the memory issues and have good performance while doing that. LGTM |
Cap the amount of buffering done by BytesPipe
Previously, BytesPipe would grow without a limit. This was dangerous if
data was written to it faster than it was read, it would exhaust available
memory.
Turn BytesPipe's Read and Write functions into blocking, goroutine-safe
functions. Add a CloseWithError function to propagate an error code to
the Read function.
Adjust tests to work with the blocking Read and Write functions.
Remove BufReader, since now its users can use BytesPipe directly.
This version of the commit hardcodes a 1 MB threshold for blocking on writes. I'm hoping that we can do some testing around this and determine if this number should be tweaked or made configurable.
cc @unclejack @vcaputo @jonathanperret