netudima commented on code in PR #4707:
URL: https://github.com/apache/cassandra/pull/4707#discussion_r3036931463
##########
src/java/org/apache/cassandra/db/ReadResponse.java:
##########
@@ -239,9 +244,15 @@ private LocalDataResponse(UnfilteredPartitionIterator
iter, ColumnFilter selecti
private static ByteBuffer build(UnfilteredPartitionIterator iter,
ColumnFilter selection)
{
- try (DataOutputBuffer buffer = new DataOutputBuffer())
+ // Size output buffer to 10% above the moving average to absorb
minor variance and limit rebuffering.
+ double bufferSizeEstimate =
Double.isNaN(estimatedResponseBytes.get()) ? 128 : estimatedResponseBytes.get();
Review Comment:
nit: better to extract estimatedResponseBytes.get() to a local variable, to
avoid an additional volatile read and longBitsToDouble invocation
##########
src/java/org/apache/cassandra/db/ReadResponse.java:
##########
@@ -239,9 +244,15 @@ private LocalDataResponse(UnfilteredPartitionIterator
iter, ColumnFilter selecti
private static ByteBuffer build(UnfilteredPartitionIterator iter,
ColumnFilter selection)
{
- try (DataOutputBuffer buffer = new DataOutputBuffer())
+ // Size output buffer to 10% above the moving average to absorb
minor variance and limit rebuffering.
+ double bufferSizeEstimate =
Double.isNaN(estimatedResponseBytes.get()) ? 128 : estimatedResponseBytes.get();
+ int initialBufferSize = (int) (bufferSizeEstimate * 1.1);
+
+ try (DataOutputBuffer buffer = new
DataOutputBuffer(initialBufferSize))
{
UnfilteredPartitionIterators.serializerForIntraNode().serialize(iter,
selection, buffer, MessagingService.current_version);
+ estimatedResponseBytes.update(buffer.position());
+
return buffer.buffer();
Review Comment:
what is about buffer.buffer(false) here to avoid ByteBuffer duplication and
save a bit more allocations?, taking in account that DataOutputBuffer is not
reused here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]