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 09:51:28 UTC

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

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



##########
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:
       to improve throughput and decrease cpu cost when tps is greater than threshold.




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