Repository navigation
Conversation
|
@Rich-T-kid, while in #10383 you focus on changing the heuristic, this PR introduces a second step after it, that directly evaluates the actual encoded size of the flight batch. If it still exceeds Maybe combining this PR with yours could be the best solution so far? (at least I could think of) |
|
yea ill close #10383 in favor of this one. |
|
run benchmark ipc_writer |
1 similar comment
|
run benchmark ipc_writer |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing flight/adaptive-grpc-response-splitting (68c48e9) to f9e02ba (merge-base) diff Run configurationrun benchmark ipc_writerBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_writer File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing flight/adaptive-grpc-response-splitting (68c48e9) to f9e02ba (merge-base) diff Run configurationrun benchmark ipc_writerBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_writer File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing flight/adaptive-grpc-response-splitting (68c48e9) to f9e02ba (merge-base) diff Run configurationrun benchmark ipc_writerCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing flight/adaptive-grpc-response-splitting (68c48e9) to f9e02ba (merge-base) diff Run configurationrun benchmark ipc_writerCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
Rich-T-kid
left a comment
There was a problem hiding this comment.
will take a closer look but for the most part this makes sense to me.
|
@DevMattG could you rebase this PR |
0b396e3 to
a5b296a
Compare
Done. Please let me know if there's something else I should do. Thanks! |
… size `split_batch_for_grpc_response` only estimates a RecordBatch's encoded size from `get_buffer_memory_size()`, which ignores IPC framing/padding overhead and can badly undercount for variable-length data (dictionaries, strings). This let `FlightDataEncoder` silently emit `FlightData` messages larger than `max_flight_data_size` (see apache#3478). `FlightDataEncoder::encode_batch` now delegates to a new `encode_piece_adaptive`, which encodes each heuristic-split piece, queues any dictionaries unconditionally (they're keyed by id and correct to send regardless of how the batch body ends up sliced), and if the *actual* encoded size still exceeds the limit, re-splits, recursively if necessary. To avoid paying for that fallback on every batch whose estimated size lands right at the limit, the first-pass heuristic now targets 90% of `max_flight_data_size` (`SPLIT_HEURISTIC_MARGIN_DIVISOR`), leaving headroom for the framing overhead the estimate doesn't account for.
a5b296a to
b68800e
Compare
azecevic000
left a comment
There was a problem hiding this comment.
@DevMattG @Rich-T-kid I believe both this PR and #10383 solve #3478 from different directions. This PR makes max_flight_data_size a hard limit (documentation should be updated in this PR).
But there is still an issue where the memory size is overestimated because the size of the underlying buffer is taken instead of the size of the encoded slice. The notable pathological case is when you want to reencode the batch that was produced during the IPC serialization. Each column counts the whole message as its own buffer size, so it depends on the schema, but often the end result will be the split which split the batch into single row batches.
I think it makes sense to incorporate #10383 into this PR, what do you guys think? Thank you both for working on #3478, hopefully this can be resolved and merged soon.
|
sorry for the delay, will spend a block of time reviewing this tommorow |
👍 I agree
I agree. would be nice to solve both of these. typically Id be in favor of splitting this into two PR's but I think they are quite related |
|
@DevMattG Kindly nudge, do you have time to work on this in the near future? I hope this can land in 61.0. I'm more than happy to offer any kind of help (reviewing or taking this to the finish line if you're out of time). CC: @Rich-T-kid |
Sorry for the delay. I was hoping to gather some time to work on this, but as a matter of fact I have no idea when I'd be able to continue. So, please feel free to take over and finish it! Sorry again :( |
|
@DevMattG No worries, thanks for letting me know! Sure, I would love to drive this to completion. I will prioritize this. |
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit, and add more than half of the limit for each additional piece, for example because each repeats the child of a list view array or a large IPC header, send the message as it is. Document the limit and its exceptions.
|
@azecevic000 should we close this pr in favor of yours? |
Yes, please. I'm working on a few more details; I plan to open a PR very soon (hopefully by the end of the day). |
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit, and add more than half of the limit for each additional piece, for example because each repeats the child of a list view array or a large IPC header, send the message as it is. - Let `IpcWriteContext` allocate the reserved scratch on the next encode, and let `set_reserve_scratch(false)` drop a pending capacity. The encoder then reserves for all pieces of a batch, instead of passing down to each split whether its piece is the last one. Document the limit and its exceptions.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit, and add more than half of the limit for each additional piece, for example because each repeats the child of a list view array or a large IPC header, send the message as it is. - Let `IpcWriteContext` allocate the reserved scratch on the next encode, and let `set_reserve_scratch(false)` drop a pending capacity. The encoder then reserves for all pieces of a batch, instead of passing down to each split whether its piece is the last one. Document the limit and its exceptions.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit and each repeats more than half of the limit, for example the child of a list view array or a large IPC header, send the message as-is. - Encode the pieces of a split message without reserving the scratch buffer of the IPC writer: every body would start with at least the capacity of the split message, which is over the limit. Document the limit and its exceptions.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit and the overhead of each piece, for example a large IPC header or the child of a list view array, is more than half of the limit, send the message as-is. - Encode the pieces of a split message without reserving the scratch buffer of the IPC writer: every body would start with at least the capacity of the split message, which is over the limit. Document the limit and its exceptions.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit and the overhead of each piece, for example a large IPC header or the child of a list view array, is more than half of the limit, send the message as-is. - Encode the pieces of a split message without reserving the scratch buffer of the IPC writer: every body would start with at least the capacity of the split message, which is over the limit. Document the limit and its exceptions.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit and the overhead of each piece, for example a large IPC header or the child of a list view array, is more than half of the limit, send the message as-is. - Encode the pieces of a split message without reserving the scratch buffer of the IPC writer: every body would start with at least the capacity of the split message, which is over the limit. Document the limit and its exceptions.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit and the overhead of each piece, for example a large IPC header or the child of a list view array, is more than half of the limit, send the message as-is. - Encode the pieces of a split message without reserving the scratch buffer of the IPC writer: every body would start with at least the capacity of the split message, which is over the limit. Document the limit and its exceptions.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit and the overhead of each piece, for example a large IPC header or the child of a list view array, is more than half of the limit, send the message as-is. - Encode the pieces of a split message without reserving the scratch buffer of the IPC writer: every body would start with at least the capacity of the split message, which is over the limit. Document the limit and its exceptions.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit and the overhead of each piece, for example a large IPC header or the child of a list view array, is more than half of the limit, send the message as-is. - Encode the pieces of a split message without reserving the scratch buffer of the IPC writer: every body would start with at least the capacity of the split message, which is over the limit. Document the limit and its exceptions.
Which issue does this PR close?
Rationale for this change
FlightDataEncodersplits record batches based on a cheap, buffer-memory-size heuristic before IPC encoding. That heuristic can be significantly wrong -- it ignores IPC framing/padding overhead, and undercounts batches with dictionaries or highly skewed row sizes -- so pieces produced by the initial split can still end up well overmax_flight_data_sizeonce actually encoded.What changes are included in this PR?
max_flight_data_sizeinFlightDataEncoder::encode_piece_adaptive. If it's still too large, the piece is re-split using the real size ratio and the sub-pieces are recursively re-checked, so oversized pieces get corrected regardless of why the initial estimate was wrong.split_batch_for_grpc_response's batch-count calculation to round up (div_ceil) instead of using floor division, which could previously produce one too few batches.Are these changes tested?
Yes. Added/extended unit tests in
arrow-flight/src/encode.rscovering:DictionaryHandling::Resendand the defaultDictionaryHandling::Hydrate.max_flight_data_size(can't be split further, must still be emitted).Are there any user-facing changes?
No breaking API changes.