kerneltime commented on code in PR #3614:
URL: https://github.com/apache/ozone/pull/3614#discussion_r932756937


##########
hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto:
##########
@@ -1453,6 +1456,23 @@ message PartInfo {
     required uint64 size = 4;
 }
 
+/**
+ Stores the raw payload of rpc request, used in OmRPCLoadGenerator
+ */
+message EchoRPCRequest {
+    optional bytes payloadReq = 1;
+    optional int32 payloadSizeResp = 2;
+    optional bool isEmptyResp = 3;

Review Comment:
   Same as above `payloadSizeResp` == 0 should server as the boolean.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/OmRPCLoadGenerator.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.RandomUtils;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import 
org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.EchoRPCResponse;
+
+import java.util.concurrent.Callable;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+/**
+ * Utility to generate RPC request to OM with or without payload.
+ */
+@Command(name = "om-rpc-load",
+        aliases = "rpcl",
+        description =
+                "Generate random RPC request to the OM " +
+                        "with or without layload.",
+        versionProvider = HddsVersionProvider.class,
+        mixinStandardHelpOptions = true,
+        showDefaultValues = true)
+public class OmRPCLoadGenerator extends BaseFreonGenerator
+        implements Callable<Void> {
+
+  private static final Logger LOG =
+          LoggerFactory.getLogger(OmRPCLoadGenerator.class);
+
+  private static final int RPC_PAYLOAD_MULTIPLICATION_FACTOR = 1024;
+
+  private Timer timer;
+
+  @Option(names = {"-plrq", "--payload-req"},
+          description =
+                  "Specifies the size of payload in KB in RPC request.",
+          defaultValue = "1")
+  private int payloadReqSizeKB = 1;
+
+  @Option(names = {"-plrp", "--payload-resp"},
+          description =
+                  "Specifies the size of payload in KB in RPC response.",
+          defaultValue = "1")
+  private int payloadRespSizeKB = 1;
+
+  @Option(names = {"-erq", "--empty-req"},

Review Comment:
   We can simplify the CLI and `0` or undefined as a proxy for false.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/OmRPCLoadGenerator.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.RandomUtils;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import 
org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.EchoRPCResponse;
+
+import java.util.concurrent.Callable;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+/**
+ * Utility to generate RPC request to OM with or without payload.
+ */
+@Command(name = "om-rpc-load",
+        aliases = "rpcl",
+        description =
+                "Generate random RPC request to the OM " +
+                        "with or without layload.",
+        versionProvider = HddsVersionProvider.class,
+        mixinStandardHelpOptions = true,
+        showDefaultValues = true)
+public class OmRPCLoadGenerator extends BaseFreonGenerator
+        implements Callable<Void> {
+
+  private static final Logger LOG =
+          LoggerFactory.getLogger(OmRPCLoadGenerator.class);
+
+  private static final int RPC_PAYLOAD_MULTIPLICATION_FACTOR = 1024;
+
+  private Timer timer;
+
+  @Option(names = {"-plrq", "--payload-req"},
+          description =
+                  "Specifies the size of payload in KB in RPC request.",
+          defaultValue = "1")
+  private int payloadReqSizeKB = 1;
+
+  @Option(names = {"-plrp", "--payload-resp"},
+          description =
+                  "Specifies the size of payload in KB in RPC response.",
+          defaultValue = "1")
+  private int payloadRespSizeKB = 1;
+
+  @Option(names = {"-erq", "--empty-req"},
+          description =
+                  "Specifies whether the payload of request is empty or not",
+          defaultValue = "False")
+  private boolean isEmptyReq = false;
+
+  @Option(names = {"-erp", "--empty-resp"},
+          description =
+                  "Specifies whether the payload of response is empty or not",
+          defaultValue = "False")
+  private boolean isEmptyResp = false;
+
+  @Override
+  public Void call() throws Exception {
+    if (payloadReqSizeKB < 0 || payloadRespSizeKB < 0) {
+      throw new IllegalArgumentException(
+              "RPC request or response payload can't be negative value."
+      );
+    }
+
+    init();
+    int numOfThreads = getThreadNo();
+    timer = getMetrics().timer("rpc-payload");
+
+    for (int i = 0; i < numOfThreads; i++) {
+      runTests(this::sendRPCReq);
+    }
+    printReport();
+    return null;
+  }
+  private void sendRPCReq(long l) throws Exception {
+    OzoneConfiguration configuration = createOzoneConfiguration();
+    OzoneManagerProtocolClientSideTranslatorPB client =
+            createOmClient(configuration, null);
+    byte[] payloadReq;
+    if (isEmptyReq) {
+      payloadReq = null;
+    } else {
+      int payloadReqSize = (int) Math.min(
+              (long)payloadReqSizeKB * RPC_PAYLOAD_MULTIPLICATION_FACTOR,
+              Integer.MAX_VALUE);
+      payloadReq = RandomUtils.nextBytes(payloadReqSize);

Review Comment:
   Same below



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerProtocol.java:
##########
@@ -908,4 +909,18 @@ default PrepareStatusResponse 
getOzoneManagerPrepareStatus(long txnId)
   default CancelPrepareResponse cancelOzoneManagerPrepare() throws IOException 
{
     return CancelPrepareResponse.newBuilder().build();
   }
+
+  /**
+   * Send RPC request with or without payload to OM
+   * to benchmark RPC communication performance.
+   * @param payloadReq payload in request.
+   * @param payloadSizeResp payload size of response.
+   * @param emptyResp if the payload of response is empty or not.
+   * @throws IOException if there is error in the RPC communication.
+   * @return EchoRPCResponse.
+   */
+  EchoRPCResponse echoRPCReq(byte[] payloadReq,
+                             int payloadSizeResp, boolean emptyResp)

Review Comment:
   I think this API can be simplified, if the response is empty the 
`payloadSizeResp` can be 0 and we can drop the boolean.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/OmRPCLoadGenerator.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.RandomUtils;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import 
org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.EchoRPCResponse;
+
+import java.util.concurrent.Callable;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+/**
+ * Utility to generate RPC request to OM with or without payload.
+ */
+@Command(name = "om-rpc-load",
+        aliases = "rpcl",
+        description =
+                "Generate random RPC request to the OM " +
+                        "with or without layload.",
+        versionProvider = HddsVersionProvider.class,
+        mixinStandardHelpOptions = true,
+        showDefaultValues = true)
+public class OmRPCLoadGenerator extends BaseFreonGenerator
+        implements Callable<Void> {
+
+  private static final Logger LOG =
+          LoggerFactory.getLogger(OmRPCLoadGenerator.class);
+
+  private static final int RPC_PAYLOAD_MULTIPLICATION_FACTOR = 1024;
+
+  private Timer timer;
+
+  @Option(names = {"-plrq", "--payload-req"},
+          description =
+                  "Specifies the size of payload in KB in RPC request.",
+          defaultValue = "1")
+  private int payloadReqSizeKB = 1;
+
+  @Option(names = {"-plrp", "--payload-resp"},
+          description =
+                  "Specifies the size of payload in KB in RPC response.",
+          defaultValue = "1")
+  private int payloadRespSizeKB = 1;
+
+  @Option(names = {"-erq", "--empty-req"},
+          description =
+                  "Specifies whether the payload of request is empty or not",
+          defaultValue = "False")
+  private boolean isEmptyReq = false;
+
+  @Option(names = {"-erp", "--empty-resp"},
+          description =
+                  "Specifies whether the payload of response is empty or not",
+          defaultValue = "False")
+  private boolean isEmptyResp = false;
+
+  @Override
+  public Void call() throws Exception {
+    if (payloadReqSizeKB < 0 || payloadRespSizeKB < 0) {
+      throw new IllegalArgumentException(
+              "RPC request or response payload can't be negative value."
+      );
+    }
+
+    init();
+    int numOfThreads = getThreadNo();
+    timer = getMetrics().timer("rpc-payload");
+
+    for (int i = 0; i < numOfThreads; i++) {
+      runTests(this::sendRPCReq);
+    }
+    printReport();
+    return null;
+  }
+  private void sendRPCReq(long l) throws Exception {
+    OzoneConfiguration configuration = createOzoneConfiguration();
+    OzoneManagerProtocolClientSideTranslatorPB client =
+            createOmClient(configuration, null);
+    byte[] payloadReq;
+    if (isEmptyReq) {
+      payloadReq = null;
+    } else {
+      int payloadReqSize = (int) Math.min(
+              (long)payloadReqSizeKB * RPC_PAYLOAD_MULTIPLICATION_FACTOR,
+              Integer.MAX_VALUE);
+      payloadReq = RandomUtils.nextBytes(payloadReqSize);

Review Comment:
   This can be cleaned up, we are covering an int to a long and then converting 
it back to int?
   I think we can cap the payload to be maximum of 256 gigs and include that in 
the cli usage as the max. This should be all doable with `int`.



-- 
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