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 2019/11/28 07:47:57 UTC

[GitHub] [pulsar] sijie commented on a change in pull request #5761: [pulsar-client] Switch partition when a batch is full (in RoundRobinMessageRouter)

sijie commented on a change in pull request #5761: [pulsar-client] Switch partition when a batch is full (in RoundRobinMessageRouter)
URL: https://github.com/apache/pulsar/pull/5761#discussion_r351629509
 
 

 ##########
 File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/RoundRobinPartitionMessageRouterImpl.java
 ##########
 @@ -79,9 +69,15 @@ public int choosePartition(Message<?> msg, TopicMetadata topicMetadata) {
             return signSafeMod(hash.makeHash(msg.getKey()), topicMetadata.numPartitions());
         }
 
-        if (isBatchingEnabled) { // if batching is enabled, choose partition on `maxBatchingDelayMs` boundary.
-            long currentMs = clock.millis();
-            return signSafeMod(currentMs / maxBatchingDelayMs + startPtnIdx, topicMetadata.numPartitions());
+        if (isBatchingEnabled) {
+            int msgSize = msg.getData().length;
+            if (msgSize + MESSAGE_BYTES_UPDATER.get(this) <= maxBatchingBytes) {
 
 Review comment:
   I don't think we need to be very accurate here. we should just use addAndGet directly.
   
   ```
   int newBatchSize = MESSAGE_BYTES_UPDATER.addAndGet(this, msg.getData().length);
   if (newBatchSize <= maxBatchingBytes) {
      return signSafeMod(PARTITION_INDEX_UPDATER.get(this), topicMetadata.numPartitions());
   } else {
      MESSAGE_BYTES_UPDATER.set(this, 0);
      return signSafeMod(PARTITION_INDEX_UPDATER.getAndIncrement(this), topicMetadata.numPartitions());
   }
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services