You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/03/19 03:51:32 UTC

[GitHub] [incubator-pinot] snleee commented on a change in pull request #5160: Add a simple PinotFS benchmark driver

snleee commented on a change in pull request #5160: Add a simple PinotFS benchmark driver
URL: https://github.com/apache/incubator-pinot/pull/5160#discussion_r394776920
 
 

 ##########
 File path: pinot-tools/src/main/java/org/apache/pinot/tools/filesystem/PinotFSBenchmarkDriver.java
 ##########
 @@ -0,0 +1,252 @@
+/**
+ * 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.tools.filesystem;
+
+import com.google.common.base.Preconditions;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.MessageDigest;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.spi.filesystem.PinotFS;
+import org.apache.pinot.spi.filesystem.PinotFSFactory;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PinotFSBenchmarkDriver {
+  private static final Logger LOGGER = LoggerFactory.getLogger(PinotFSBenchmarkDriver.class);
+
+  private static final int DEFAULT_NUM_SEGMENTS_FOR_LIST_TEST = 1000;
+  private static final int DEFAULT_DATA_SIZE_IN_MB_FOR_COPY_TEST = 1024; // 1GB
+  private static final int DEFAULT_RETRY = 5; // 5
+
+  private String _mode;
+  private PinotFS _pinotFS;
+  private URI _baseDirectoryUri;
+  private File _localTempDir;
+  private int _numSegmentsForListFilesTest;
+  private int _dataSizeInMBsForCopyTest;
+
+  public PinotFSBenchmarkDriver(String mode, String configFilePath, String baseDirectoryUri, String localTempDir,
+      Integer numSegmentsForListFilesTest, Integer dataSizeInMBsForCopyTest) throws ConfigurationException {
+    Configuration configuration = new PropertiesConfiguration(new File(configFilePath));
+    PinotFSFactory.init(configuration);
+    _mode = mode;
+    _baseDirectoryUri = URI.create(baseDirectoryUri);
+    _pinotFS = PinotFSFactory.create(_baseDirectoryUri.getScheme());
+    _localTempDir =
+        (localTempDir != null) ? new File(localTempDir) : new File(FileUtils.getTempDirectory(), "benchmark");
+    _numSegmentsForListFilesTest =
+        (numSegmentsForListFilesTest != null) ? numSegmentsForListFilesTest : DEFAULT_NUM_SEGMENTS_FOR_LIST_TEST;
+    _dataSizeInMBsForCopyTest =
+        (dataSizeInMBsForCopyTest != null) ? dataSizeInMBsForCopyTest : DEFAULT_DATA_SIZE_IN_MB_FOR_COPY_TEST;
+    LOGGER.info("PinotFS has been initialized sucessfully. (mode = {}, pinotFSClass = {}, configFile = {}, "
+            + "baseDirectoryUri = {}, localTempDir = {}, numSegmentsForListFilesTest = {}, "
+            + "dataSizeInMBsForCopyTest = {})", _mode, _pinotFS.getClass().getSimpleName(), configFilePath,
+        baseDirectoryUri, _localTempDir, _numSegmentsForListFilesTest, _dataSizeInMBsForCopyTest);
+  }
+
+  public void run() throws Exception {
+    prepareBenchmark();
+
+    switch (_mode.toUpperCase()) {
+      case "ALL":
+        testListFilesInMultipleDirectories();
+        testListFiles();
+        testCopies();
+        break;
+      case "LISTFILES":
+        testListFiles();
+        break;
+      case "COPY":
+        testCopies();
+        break;
+      default:
+        throw new RuntimeException("Not Supported Mode: " + _mode);
+    }
+    cleanUpBenchmark();
+  }
+
+  private void prepareBenchmark() throws IOException {
+    // Clean up base directory
+    if (_pinotFS.exists(_baseDirectoryUri)) {
+      _pinotFS.delete(_baseDirectoryUri, true);
+    }
+
+    if (_localTempDir.exists()) {
+      _localTempDir.delete();
+    }
+
+    // Set up the base directory
+    _pinotFS.mkdir(_baseDirectoryUri);
+    _localTempDir.mkdir();
+  }
+
+  private void cleanUpBenchmark() throws IOException {
+    _pinotFS.delete(_baseDirectoryUri, true);
+    FileUtils.deleteQuietly(_localTempDir);
+    LOGGER.info("Working directories have been cleaned up successfully.");
 
 Review comment:
   added the directory names to the log.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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