You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/01/20 06:31:02 UTC

[GitHub] [rocketmq] dongeforever commented on a change in pull request #3659: [ISSUE #3585] [Part K] move execution of notifyMessageArriving() from ReputMessageService thread to PullRequestHoldService thread

dongeforever commented on a change in pull request #3659:
URL: https://github.com/apache/rocketmq/pull/3659#discussion_r788380029



##########
File path: broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullNotifyQueue.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.broker.longpolling;
+
+import java.util.LinkedList;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+class PullNotifyQueue<T> {
+    private PullNotifyQueueConfig config;
+
+    private final LinkedBlockingQueue<T> queue;
+
+    private int activeConsumeQueueCount = 1;
+    private long activeConsumeQueueEpochTime = System.nanoTime();
+    // only change in unit test
+    private long activeConsumeQueueRefreshTime = 1_000_000_000;
+
+    private long lastBatchDrainTime;
+
+    public PullNotifyQueue(PullNotifyQueueConfig config) {
+        queue = new LinkedBlockingQueue<>(500_000);
+        this.config = config;
+    }
+
+    public void put(T data) throws InterruptedException {
+        queue.put(data);
+    }
+
+    public LinkedList<T> drain() throws InterruptedException {
+        LinkedList<T> result = new LinkedList<>();
+        long tps = config.getTps();
+        if (tps <= config.getTpsThreshold()) {
+            T data = queue.poll(100, TimeUnit.MILLISECONDS);

Review comment:
       Why use the store put Tps to control the long polling?
   

##########
File path: broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullNotifyQueue.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.broker.longpolling;
+
+import java.util.LinkedList;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+class PullNotifyQueue<T> {
+    private PullNotifyQueueConfig config;
+
+    private final LinkedBlockingQueue<T> queue;
+
+    private int activeConsumeQueueCount = 1;
+    private long activeConsumeQueueEpochTime = System.nanoTime();
+    // only change in unit test
+    private long activeConsumeQueueRefreshTime = 1_000_000_000;
+
+    private long lastBatchDrainTime;
+
+    public PullNotifyQueue(PullNotifyQueueConfig config) {
+        queue = new LinkedBlockingQueue<>(500_000);
+        this.config = config;
+    }
+
+    public void put(T data) throws InterruptedException {
+        queue.put(data);
+    }
+
+    public LinkedList<T> drain() throws InterruptedException {
+        LinkedList<T> result = new LinkedList<>();
+        long tps = config.getTps();
+        if (tps <= config.getTpsThreshold()) {
+            T data = queue.poll(100, TimeUnit.MILLISECONDS);
+            if (data != null) {
+                result.add(data);
+            }
+        } else {

Review comment:
       The expectation here is :
   * if the queue has data, poll it as quickly as possible
   * if the queue doesn't have data, just return the already polled data.
   
   The code maybe be simplified as:
   int pollWaitTimeMs = 0;
   while(true) {
       T data = queue.poll(pollWaitTimeMs, TimeUnit.MILLISECONDS);
       if (data == null) {
         pollWaitTimeMs = 100;
      } else { 
        pollWaitTimeMs = 0;
        result.add(data);
      }
      if(result.size() > batchMax) {
         break;
      }
      if(result.size() >0 && pollWaitTimeMs > 0) {
        break;
      }
      if(System.nanoTime() - start > maxWaitTimeNonas) {
       break;
    }
   }
   
   The tps control seems unnecessary.
   




-- 
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: dev-unsubscribe@rocketmq.apache.org

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