yuz10 commented on a change in pull request #3718:
URL: https://github.com/apache/rocketmq/pull/3718#discussion_r780647851



##########
File path: 
client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java
##########
@@ -323,28 +340,54 @@ public void shutdown() {
      * @param msg Message to send.
      * @return {@link SendResult} instance to inform senders details of the 
deliverable, say Message ID of the message,
      * {@link SendStatus} indicating broker storage/replication status, 
message queue sent to, etc.
-     * @throws MQClientException if there is any client error.
-     * @throws RemotingException if there is any network-tier error.
-     * @throws MQBrokerException if there is any error with broker.
+     * @throws MQClientException    if there is any client error.
+     * @throws RemotingException    if there is any network-tier error.
+     * @throws MQBrokerException    if there is any error with broker.
      * @throws InterruptedException if the sending thread is interrupted.
      */
+
+    private boolean canBatch(Message msg) {
+        // produceAccumulator is full
+        if (!produceAccumulator.tryAddMessage(msg)) {
+            return false;
+        }
+        // delay message do not support batch processing
+        if (msg.getDelayTimeLevel() > 0) {
+            return false;
+        }
+        // retry message do not support batch processing
+        if (msg.getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
+            return false;
+        }
+        // message which have been assigned to producer group do not support 
batch processing
+        if 
(msg.getProperties().containsKey(MessageConst.PROPERTY_PRODUCER_GROUP)) {
+            return false;
+        }
+        return true;
+    }
+
     @Override
     public SendResult send(
         Message msg) throws MQClientException, RemotingException, 
MQBrokerException, InterruptedException {
         msg.setTopic(withNamespace(msg.getTopic()));
-        return this.defaultMQProducerImpl.send(msg);
+
+        if (this.getAutoBatch() && !(msg instanceof MessageBatch)) {
+            return sendByAccumulator(msg, null, null);

Review comment:
       We can use the benchmark to test whether the throughput is increased, 
and how many threads should use. If on most cases    the tps is worse, I would 
still recommend to disable batch support in sync mode

##########
File path: 
client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java
##########
@@ -323,28 +340,54 @@ public void shutdown() {
      * @param msg Message to send.
      * @return {@link SendResult} instance to inform senders details of the 
deliverable, say Message ID of the message,
      * {@link SendStatus} indicating broker storage/replication status, 
message queue sent to, etc.
-     * @throws MQClientException if there is any client error.
-     * @throws RemotingException if there is any network-tier error.
-     * @throws MQBrokerException if there is any error with broker.
+     * @throws MQClientException    if there is any client error.
+     * @throws RemotingException    if there is any network-tier error.
+     * @throws MQBrokerException    if there is any error with broker.
      * @throws InterruptedException if the sending thread is interrupted.
      */
+
+    private boolean canBatch(Message msg) {
+        // produceAccumulator is full
+        if (!produceAccumulator.tryAddMessage(msg)) {
+            return false;
+        }
+        // delay message do not support batch processing
+        if (msg.getDelayTimeLevel() > 0) {
+            return false;
+        }
+        // retry message do not support batch processing
+        if (msg.getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
+            return false;
+        }
+        // message which have been assigned to producer group do not support 
batch processing
+        if 
(msg.getProperties().containsKey(MessageConst.PROPERTY_PRODUCER_GROUP)) {
+            return false;
+        }
+        return true;
+    }
+
     @Override
     public SendResult send(
         Message msg) throws MQClientException, RemotingException, 
MQBrokerException, InterruptedException {
         msg.setTopic(withNamespace(msg.getTopic()));
-        return this.defaultMQProducerImpl.send(msg);
+
+        if (this.getAutoBatch() && !(msg instanceof MessageBatch)) {
+            return sendByAccumulator(msg, null, null);

Review comment:
       We can use the benchmark to test whether the throughput is increased, 
and how many threads should use. If on most cases    the tps is worse, I would 
still recommend to disable batch support in sync mode




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


Reply via email to