You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/05/09 08:29:00 UTC

[GitHub] [ozone] rakeshadr commented on a diff in pull request #3383: HDDS-6619. Add freon command to run r/w mix workload using ObjectStore APIs

rakeshadr commented on code in PR #3383:
URL: https://github.com/apache/ozone/pull/3383#discussion_r867761269


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/OmBucketReadWriteKeyOps.java:
##########
@@ -0,0 +1,309 @@
+/**
+ * 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.commons.lang3.RandomStringUtils;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.client.OzoneKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.CompletionService;
+import java.util.concurrent.ExecutorCompletionService;
+
+/**
+ * Synthetic read/write key operations workload generator tool.
+ */
+@Command(name = "obrwk",
+    aliases = "om-bucket-read-write-key-ops",
+    description = "Creates keys, performs respective read/write " +
+        "operations to measure lock performance.",
+    versionProvider = HddsVersionProvider.class,
+    mixinStandardHelpOptions = true,
+    showDefaultValues = true)
+
+public class OmBucketReadWriteKeyOps extends BaseFreonGenerator
+    implements Callable<Void> {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(OmBucketReadWriteKeyOps.class);
+
+  @Option(names = {"-v", "--volume"},
+      description = "Name of the volume 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 = {"-k", "--key-count-for-read"},
+      description = "Number of keys to be created for read operations.",
+      defaultValue = "100")
+  private int keyCountForRead;
+
+  @Option(names = {"-w", "--key-count-for-write"},
+      description = "Number of keys to be created for write operations.",
+      defaultValue = "10")
+  private int keyCountForWrite;
+
+  @Option(names = {"-g", "--key-size"},
+      description = "Size of the generated key (in bytes).",
+      defaultValue = "256")
+  private long keySizeInBytes;
+
+  @Option(names = {"-B", "--buffer"},
+      description = "Size of buffer used to generated the key content.",
+      defaultValue = "64")
+  private int bufferSize;
+
+  @Option(names = {"-l", "--name-len"},
+      description = "Length of the random name of path you want to create.",
+      defaultValue = "10")
+  private int length;
+
+  @Option(names = {"-c", "--total-thread-count"},
+      description = "Total number of threads to be executed.",
+      defaultValue = "100")
+  private int totalThreadCount;
+
+  @Option(names = {"-T", "--read-thread-percentage"},
+      description = "Percentage of the total number of threads to be " +
+          "allocated for read operations. The remaining percentage of " +
+          "threads will be allocated for write operations.",
+      defaultValue = "90")
+  private int readThreadPercentage;
+
+  @Option(names = {"-R", "--num-of-read-operations"},
+      description = "Number of read operations to be performed by each thread.",
+      defaultValue = "50")
+  private int numOfReadOperations;
+
+  @Option(names = {"-W", "--num-of-write-operations"},
+      description = "Number of write operations to be performed by each " +
+          "thread.",
+      defaultValue = "10")
+  private int numOfWriteOperations;
+
+  @Option(names = {"-o", "--om-service-id"},
+      description = "OM Service ID"
+  )
+  private String omServiceID = null;
+
+  @CommandLine.Mixin
+  private FreonReplicationOptions replication;
+
+  private Timer timer;
+
+  private ContentGenerator contentGenerator;
+
+  private Map<String, String> metadata;
+
+  private ReplicationConfig replicationConfig;
+
+  private OzoneBucket bucket;
+
+  private int readThreadCount;
+  private int writeThreadCount;
+
+  @Override
+  public Void call() throws Exception {
+    init();
+
+    readThreadCount = (readThreadPercentage * totalThreadCount) / 100;
+    writeThreadCount = totalThreadCount - readThreadCount;
+
+    print("volumeName: " + volumeName);
+    print("bucketName: " + bucketName);
+    print("keyCountForRead: " + keyCountForRead);
+    print("keyCountForWrite: " + keyCountForWrite);
+    print("keySizeInBytes: " + keySizeInBytes);
+    print("bufferSize: " + bufferSize);
+    print("totalThreadCount: " + totalThreadCount);
+    print("readThreadPercentage: " + readThreadPercentage);
+    print("writeThreadPercentage: " + (100 - readThreadPercentage));
+    print("readThreadCount: " + readThreadCount);
+    print("writeThreadCount: " + writeThreadCount);
+    print("numOfReadOperations: " + numOfReadOperations);
+    print("numOfWriteOperations: " + numOfWriteOperations);
+    print("omServiceID: " + omServiceID);
+
+    OzoneConfiguration ozoneConfiguration = createOzoneConfiguration();
+    replicationConfig = replication.fromParamsOrConfig(ozoneConfiguration);
+
+    contentGenerator = new ContentGenerator(keySizeInBytes, bufferSize);
+    metadata = new HashMap<>();
+
+    try (OzoneClient rpcClient = createOzoneClient(omServiceID,
+        ozoneConfiguration)) {
+      ensureVolumeAndBucketExist(rpcClient, volumeName, bucketName);
+      bucket = rpcClient.getObjectStore().getVolume(volumeName)
+          .getBucket(bucketName);
+
+      timer = getMetrics().timer("key-create");
+
+      runTests(this::mainMethod);
+    }
+
+    return null;
+  }
+
+  private void mainMethod(long counter) throws Exception {
+
+    int readResult = readOperations();
+    int writeResult = writeOperations();
+
+    print("Total Keys Read: " + readResult);
+    print("Total Keys Written: " + writeResult * keyCountForWrite);
+
+    // TODO: print read/write lock metrics (HDDS-6435, HDDS-6436).
+  }
+
+  private int readOperations() throws Exception {
+
+    // Create keyCountForRead (defaultValue = 100) keys under
+    // rootPath/readPath
+    String readPath = "".concat(OzoneConsts.OM_KEY_PREFIX).concat("readPath");
+    createKeys(readPath, keyCountForRead);
+
+    // Start readThreadCount (defaultValue = 90) concurrent read threads
+    // performing numOfReadOperations (defaultValue = 50) iterations
+    // of read operations (bucket.listKeys(readPath))
+    ExecutorService readService = Executors.newFixedThreadPool(readThreadCount);

Review Comment:
   It looks like `OmBucketReadWriteFileOps` and `OmBucketReadWriteKeyOps` has similar behaviors except the FS and ObjectStore specific apis. How about to keep the common code to an abstract class and expose specific functions. Those functions can be overridden by `fileOps` and `keyOps` specific classes.
   
   ```
   AbstractOmBucketReadWriteOps 
       | -> OmBucketReadWriteFileOps : Here need to initialize fs and override r/w methods
       | -> OmBucketReadWriteKeyOps : Here need to initialize obs and override r/w methods
   ```
   ```
   
   abstract class AbstractOmBucketReadWriteOps  extends BaseFreonGenerator
       implements Callable<Void>{
   
   // Here we can keep all the common functions
   
   // Then expose abstract methods like,
   
   // for specific write logic
   protected createKey(String path);
   
   // for specific read logic
   protected int readOperations();
   
   }
   ```



-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org