zhuzhurk commented on a change in pull request #15199: URL: https://github.com/apache/flink/pull/15199#discussion_r599253364
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/io/disk/BatchShuffleReadIOExecutor.java ########## @@ -0,0 +1,127 @@ +/* + * 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.flink.runtime.io.disk; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.runtime.util.ExecutorThreadFactory; +import org.apache.flink.runtime.util.Hardware; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.GuardedBy; + +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +import static org.apache.flink.util.Preconditions.checkArgument; +import static org.apache.flink.util.Preconditions.checkState; + +/** + * A fixed-size {@link Executor} pool used by batch shuffle for shuffle data read (currently only + * used by sort-merge blocking shuffle. + */ +@Internal +public class BatchShuffleReadIOExecutor implements Executor { + + /** Minimum valid number of executor threads. */ + public static final int MIN_NUM_THREADS = 4; + + /** Maximum valid number of executor threads. */ + public static final int MAX_NUM_THREADS = Math.max(4, 4 * Hardware.getNumberCPUCores()); + + /** Lock for protecting thread-unsafe fields. */ + private final Object lock = new Object(); + + /** Number of threads in this executor pool. */ + private final int numThreads; + + /** Underlying executor service to run tasks. */ + @GuardedBy("lock") + private ExecutorService executors; + + /** + * Whether this executor pool has been destroyed or not. If destroyed, no task can be executed + * any more. + */ + @GuardedBy("lock") + private boolean destroyed; + + public BatchShuffleReadIOExecutor(int numThreads) { + checkArgument( + numThreads >= MIN_NUM_THREADS && numThreads <= MAX_NUM_THREADS, + String.format( + "Illegal thread number, must be no smaller than %d and no larger than %d.", + MIN_NUM_THREADS, MAX_NUM_THREADS)); + this.numThreads = numThreads; + } + + public int getNumThreads() { Review comment: it's not needed I guess. -- 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: [email protected]
