lnbest0707-uber commented on code in PR #14686:
URL: https://github.com/apache/pinot/pull/14686#discussion_r1934441447


##########
pinot-server/src/main/java/org/apache/pinot/server/predownload/PredownloadScheduler.java:
##########
@@ -0,0 +1,423 @@
+/**
+ * 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.pinot.server.predownload;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.common.utils.TarCompressionUtils;
+import org.apache.pinot.common.utils.fetcher.SegmentFetcherFactory;
+import org.apache.pinot.server.conf.ServerConf;
+import org.apache.pinot.server.starter.helix.HelixInstanceDataManagerConfig;
+import org.apache.pinot.spi.config.instance.InstanceDataManagerConfig;
+import org.apache.pinot.spi.crypt.PinotCrypterFactory;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.filesystem.PinotFSFactory;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.apache.pinot.spi.utils.retry.AttemptsExceededException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PredownloadScheduler {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PredownloadScheduler.class);
+  private static final String TMP_DIR_NAME = "tmp";
+  // Segment download dir in format of "tmp-" + segmentName + "-" + 
UUID.randomUUID()
+  private static final String TMP_DIR_FORMAT = "tmp-%s-%s";
+  private static final long DOWNLOAD_SEGMENTS_TIMEOUT_MIN = 60;
+  private static final long LOAD_SEGMENTS_TIMEOUT_MIN = 5;
+  private final PropertiesConfiguration _properties;
+  private final PinotConfiguration _pinotConfig;
+  private final InstanceDataManagerConfig _instanceDataManagerConfig;
+  private final String _clusterName;
+  private final String _instanceId;
+  private final String _zkAddress;
+  @VisibleForTesting
+  Executor _executor;
+  @VisibleForTesting
+  Set<String> _failedSegments;
+  @SuppressWarnings("NullAway.Init")
+  private PredownloadMetrics _predownloadMetrics;
+  private int _numOfSkippedSegments;
+  private int _numOfUnableToDownloadSegments;
+  private int _numOfDownloadSegments;
+  private long _totalDownloadedSizeBytes;
+  @SuppressWarnings("NullAway.Init")
+  private ZKClient _zkClient;
+  @SuppressWarnings("NullAway.Init")
+  private List<SegmentInfo> _segmentInfoList;
+  @SuppressWarnings("NullAway.Init")
+  private Map<String, TableInfo> _tableInfoMap;
+
+  public PredownloadScheduler(PropertiesConfiguration properties)
+      throws Exception {
+    _properties = properties;
+    _clusterName = 
properties.getString(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME);
+    _zkAddress = 
properties.getString(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER);
+    _instanceId = 
properties.getString(CommonConstants.Server.CONFIG_OF_INSTANCE_ID);
+    _pinotConfig = new PinotConfiguration(properties);
+    _instanceDataManagerConfig =
+        new HelixInstanceDataManagerConfig(new 
ServerConf(_pinotConfig).getInstanceDataManagerConfig());
+    // Get the number of available processors (vCPUs)
+    int numProcessors = Runtime.getRuntime().availableProcessors();
+    _failedSegments = ConcurrentHashMap.newKeySet();
+    // TODO: tune the value
+    _executor = Executors.newFixedThreadPool(numProcessors * 3);

Review Comment:
   There are 3 types of potential bottlenecks: network, disk and CPU.
   In my test environment, network is usually not unless all servers on the 
same rack are all doing intense IO.
   CPU is used as there are many decompression jobs. But as long as each core 
is always assigned to decompress segments, it should be optimal.
   Disk is usually the bottleneck as both downloading and decompression use 
disks a lot.
   
   With num of executors > numProcessors *2, speed does not change much in my 
tests. *3 is good in most of times, a too high value would be even slower.



-- 
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...@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to