zddr commented on code in PR #45103: URL: https://github.com/apache/doris/pull/45103#discussion_r1879236729
########## fe/fe-core/src/main/java/org/apache/doris/job/disruptor/TaskDisruptor.java: ########## @@ -73,20 +73,42 @@ public void start() { */ public boolean publishEvent(Object... args) { try { - RingBuffer<T> ringBuffer = disruptor.getRingBuffer(); - // Check if the RingBuffer has enough capacity to reserve 10 slots for tasks - // If there is insufficient capacity (less than 10 slots available) - // log a warning and drop the current task - if (!ringBuffer.hasAvailableCapacity(10)) { - LOG.warn("ring buffer has no available capacity,task will be dropped," - + "please check the task queue size."); - return false; + // Set the timeout to 1 second, converted to nanoseconds for precision + long timeoutInNanos = TimeUnit.SECONDS.toNanos(1); // Timeout set to 1 second + long startTime = System.nanoTime(); // Record the start time + + // Loop until the timeout is reached + while (System.nanoTime() - startTime < timeoutInNanos) { + // Check if there is enough remaining capacity in the ring buffer + // Adjusting to check if the required capacity is available (instead of hardcoding 1) + if (disruptor.getRingBuffer().remainingCapacity() > 1) { + // Publish the event if there is enough capacity Review Comment: Will there be concurrency? When making a judgment, it is greater than 1, and when publishing, there is no capacity left ########## fe/fe-core/src/main/java/org/apache/doris/job/disruptor/TaskDisruptor.java: ########## @@ -73,20 +73,42 @@ public void start() { */ public boolean publishEvent(Object... args) { try { - RingBuffer<T> ringBuffer = disruptor.getRingBuffer(); - // Check if the RingBuffer has enough capacity to reserve 10 slots for tasks - // If there is insufficient capacity (less than 10 slots available) - // log a warning and drop the current task - if (!ringBuffer.hasAvailableCapacity(10)) { - LOG.warn("ring buffer has no available capacity,task will be dropped," - + "please check the task queue size."); - return false; + // Set the timeout to 1 second, converted to nanoseconds for precision + long timeoutInNanos = TimeUnit.SECONDS.toNanos(1); // Timeout set to 1 second + long startTime = System.nanoTime(); // Record the start time + + // Loop until the timeout is reached + while (System.nanoTime() - startTime < timeoutInNanos) { + // Check if there is enough remaining capacity in the ring buffer + // Adjusting to check if the required capacity is available (instead of hardcoding 1) + if (disruptor.getRingBuffer().remainingCapacity() > 1) { + // Publish the event if there is enough capacity + disruptor.getRingBuffer().publishEvent(eventTranslator, args); + if (LOG.isDebugEnabled()) { + LOG.debug("publishEvent success,the remaining buffer size is {}", + disruptor.getRingBuffer().remainingCapacity()); Review Comment: What is the purpose of this operation? ########## fe/fe-core/src/main/java/org/apache/doris/job/executor/TaskProcessor.java: ########## @@ -0,0 +1,87 @@ +// 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.doris.job.executor; + +import org.apache.doris.job.task.AbstractTask; + +import lombok.extern.log4j.Log4j2; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +@Log4j2 +public class TaskProcessor { + private ExecutorService executor; + + public TaskProcessor(int numberOfThreads, int queueSize, ThreadFactory threadFactory) { + this.executor = new ThreadPoolExecutor( + numberOfThreads, + numberOfThreads, + 0L, TimeUnit.MILLISECONDS, + new ArrayBlockingQueue<>(queueSize), + threadFactory, + new ThreadPoolExecutor.AbortPolicy() + ); + } + + public boolean addTask(AbstractTask task) { + try { + executor.execute(() -> runTask(task)); // 直接提交任务 Review Comment: english -- 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-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org