You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/09/29 11:27:32 UTC

[GitHub] [pulsar] Jason918 commented on a diff in pull request #17854: [improve][java-client]Shrink BatchMessageContainer maxBatchSize

Jason918 commented on code in PR #17854:
URL: https://github.com/apache/pulsar/pull/17854#discussion_r983421820


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageContainerImpl.java:
##########
@@ -167,10 +170,27 @@ private ByteBuf getCompressedBatchMetadataAndPayload() {
 
         // Update the current max batch size using the uncompressed size, which is what we need in any case to
         // accumulate the batch content
-        maxBatchSize = Math.max(maxBatchSize, uncompressedSize);
+        updateMaxBatchSize(uncompressedSize);
         return compressedPayload;
     }
 
+    void updateMaxBatchSize(int uncompressedSize) {
+        if (uncompressedSize > maxBatchSize) {
+            maxBatchSize = uncompressedSize;
+            consecutiveShrinkTime = 0;
+        } else {
+            int shrank = maxBatchSize - (maxBatchSize >> 2);
+            if (uncompressedSize <= shrank) {

Review Comment:
   Maybe, set `consecutiveShrinkTime` = 0 if `uncompressedSize > shrank`



##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/BatchMessageContainerImplTest.java:
##########
@@ -36,6 +38,33 @@
 
 public class BatchMessageContainerImplTest {
 
+    @Test
+    public void testUpdateMaxBatchSize() {
+        int SHRINK_COOLING_OFF_PERIOD = 10;
+        BatchMessageContainerImpl messageContainer = new BatchMessageContainerImpl();
+        // test expand

Review Comment:
   Check the init state here?



##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/BatchMessageContainerImplTest.java:
##########
@@ -36,6 +38,33 @@
 
 public class BatchMessageContainerImplTest {
 
+    @Test
+    public void testUpdateMaxBatchSize() {
+        int SHRINK_COOLING_OFF_PERIOD = 10;
+        BatchMessageContainerImpl messageContainer = new BatchMessageContainerImpl();
+        // test expand
+        messageContainer.updateMaxBatchSize(2048);
+        assertEquals(messageContainer.getMaxBatchSize(), 2048);
+
+        // test cooling-off period
+        messageContainer.updateMaxBatchSize(2);
+        assertEquals(messageContainer.getMaxBatchSize(), 2048);
+
+        // test shrink
+        for (int i = 0; i < 15; ++i) {
+            messageContainer.updateMaxBatchSize(2);
+            if (i < SHRINK_COOLING_OFF_PERIOD) {

Review Comment:
   Add a case to verify like `messageContainer.updateMaxBatchSize(2000)`;
   



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org