jojochuang commented on a change in pull request #3140:
URL: https://github.com/apache/ozone/pull/3140#discussion_r820534043



##########
File path: 
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/OMThroughputBenchmark.java
##########
@@ -0,0 +1,483 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.freon;
+
+import com.codahale.metrics.Timer;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.client.RatisReplicationConfig;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
+import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
+import org.apache.hadoop.ozone.om.helpers.OmKeyArgs.Builder;
+import org.apache.hadoop.ozone.om.helpers.OpenKeySession;
+import org.apache.hadoop.ozone.om.helpers.OzoneAclUtil;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
+import static 
org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.ALL;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+import picocli.CommandLine.Option;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.concurrent.Callable;
+
+/**
+ * Benchmark for OM throughput (two categories).
+ * - object store
+ * - fs
+ * <p>
+ * Remember to add the following configs to your ozone-site.xml:
+ * - ozone.key.preallocation.max.blocks: 0
+ * - ozone.block.deleting.service.interval: 7d
+ */
[email protected](name = "om-throughput-benchmark",
+    aliases = "otb",
+    description = "Benchmark for om throughput.",
+    versionProvider = HddsVersionProvider.class,
+    mixinStandardHelpOptions = true,
+    showDefaultValues = true)
+public class OMThroughputBenchmark extends BaseFreonGenerator
+    implements Callable<Void> {
+
+  /**
+   * The constant LOG.
+   */
+  public static final Logger LOG =
+      LoggerFactory.getLogger(OMThroughputBenchmark.class);
+
+  @CommandLine.Option(names = {"--benchmark"},
+      description = "Which type of benchmark to run, expected one of " +
+          "[CREATEKEY, DELETEKEY, GETKEY, RENAMEKEY, LISTKEY," +
+          " CREATEFILE, DELETEFILE, OPENFILE, RENAMEFILE, FILESTATUS]",
+      required = true)
+  private BenchmarkType benchmarkType;
+
+  @Option(names = {"-v", "--volume"},
+      description = "Name of the bucket which contains the test data. Will be"
+          + " created if missing.",
+      defaultValue = "vol1")
+  private String volumeName;
+
+  @Option(names = {"-b", "--bucket"},
+      description = "Name of the bucket which contains the test data. Will be"
+          + " created if missing.",
+      defaultValue = "bucket1")
+  private String bucketName;
+
+  @Option(names = {"-F", "--factor"},
+      description = "Replication factor (ONE, THREE)",
+      defaultValue = "THREE"
+  )
+  private ReplicationFactor factor;
+
+  @Option(names = {"--om-service-id"},
+      description = "OM Service ID"
+  )
+  private String omServiceID;
+
+  @Option(names = {"-u", "--useExisting"},
+      description = "do not generate keys, use existing ones"
+  )
+  private boolean useExisting;
+
+  private OzoneConfiguration configuration;
+
+  private OzoneClient ozoneClient;
+
+  private OzoneManagerProtocol ozoneManagerClient;
+
+  private ApiTask task;
+
+
+  /**
+   * Type of benchmarks.
+   */
+  public enum BenchmarkType {
+    // - Object store
+    // -- Key level
+    CREATEKEY,
+    DELETEKEY,
+    RENAMEKEY,
+    GETKEY,
+    LISTKEY,
+    // -- Bucket level
+    // -- Volume level
+
+    // - FS
+    CREATEFILE,
+    DELETEFILE,
+    OPENFILE,
+    RENAMEFILE,
+    FILESTATUS,
+  }
+
+  @Override
+  public Void call() throws Exception {
+    configuration = createOzoneConfiguration();
+
+    init();
+
+    initClients();
+
+    prepareTask();
+
+    runTests(task::runTask);
+
+    closeClient();
+
+    return null;
+  }
+
+  private void prepareTask() throws Exception {
+
+    switch (benchmarkType) {
+    case CREATEKEY:
+      task = new CreateKeyTask();
+      break;
+    case DELETEKEY:
+      task = new DeleteKeyTask();
+      break;
+    case GETKEY:
+      task = new GetKeyTask();
+      break;
+    case RENAMEKEY:
+      task = new RenameKeyTask();
+      break;
+    case LISTKEY:
+      task = new ListKeyTask();
+      break;
+
+    case CREATEFILE:
+      task = new CreateFileTask();
+      break;
+    case OPENFILE:
+      task = new OpenFileTask();
+      break;
+    case DELETEFILE:
+      task = new DeleteFileTask();
+      break;
+    case FILESTATUS:
+      task = new FileStatusTask();
+      break;
+    case RENAMEFILE:
+      task = new RenameFileTask();
+      break;
+    default:
+      throw new IllegalArgumentException(benchmarkType +
+          " is not a valid benchmarkType.");
+    }
+
+    task.prepare();
+
+  }
+
+  private void initClients() throws Exception {
+    LOG.info("init omClient.");
+    ozoneManagerClient = createOmClient(configuration, omServiceID);
+
+    LOG.info("init ozoneClient.");
+    ozoneClient = createOzoneClient(omServiceID, configuration);
+  }
+
+  private void closeClient() throws IOException {
+    if (ozoneManagerClient != null) {
+      ozoneManagerClient.close();
+    }
+  }

Review comment:
       Close ozoneClient here too?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to