netudima commented on code in PR #4739:
URL: https://github.com/apache/cassandra/pull/4739#discussion_r3074782734


##########
src/java/org/apache/cassandra/db/ReadResponse.java:
##########
@@ -239,10 +247,21 @@ private LocalDataResponse(UnfilteredPartitionIterator 
iter, ColumnFilter selecti
 
         private static ByteBuffer build(UnfilteredPartitionIterator iter, 
ColumnFilter selection)
         {
-            try (DataOutputBuffer buffer = new DataOutputBuffer())
+            int initialBufferSize = bufferInitialSizeMin;
+
+            if (bufferInitialSizeMax > bufferInitialSizeMin)
+            {
+                // Size output buffer to 10% above the moving average to 
absorb minor variance and limit rebuffering.
+                double estimatedResponseSize = estimatedResponseBytes.get();
+                double bufferSizeEstimate = 
Double.isNaN(estimatedResponseSize) ? bufferInitialSizeMin : 
estimatedResponseSize * 1.1;
+                initialBufferSize = Math.min((int) bufferSizeEstimate, 
bufferInitialSizeMax);
+            }
+
+            try (DataOutputBuffer buffer = new 
DataOutputBuffer(initialBufferSize))
             {
                 
UnfilteredPartitionIterators.serializerForIntraNode().serialize(iter, 
selection, buffer, MessagingService.current_version);
-                return buffer.buffer();
+                estimatedResponseBytes.update(buffer.position());

Review Comment:
   nit: do we need to spend time to update MovingAverage if the dynamic logic 
is disabled (bufferInitialSizeMax <= bufferInitialSizeMin)?



-- 
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]

Reply via email to