Skip to content

Commit

Permalink
test: allow set request/response size in interop soak test (grpc#10465)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanli-ml authored Aug 10, 2023
1 parent 3b61799 commit cebb465
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2007,18 +2007,21 @@ public Status getStatus() {
}

private SoakIterationResult performOneSoakIteration(
TestServiceGrpc.TestServiceBlockingStub soakStub) throws Exception {
TestServiceGrpc.TestServiceBlockingStub soakStub, int soakRequestSize, int soakResponseSize)
throws Exception {
long startNs = System.nanoTime();
Status status = Status.OK;
try {
final SimpleRequest request =
SimpleRequest.newBuilder()
.setResponseSize(314159)
.setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828])))
.setResponseSize(soakResponseSize)
.setPayload(
Payload.newBuilder().setBody(ByteString.copyFrom(new byte[soakRequestSize])))
.build();
final SimpleResponse goldenResponse =
SimpleResponse.newBuilder()
.setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[314159])))
.setPayload(
Payload.newBuilder().setBody(ByteString.copyFrom(new byte[soakResponseSize])))
.build();
assertResponse(goldenResponse, soakStub.unaryCall(request));
} catch (StatusRuntimeException e) {
Expand All @@ -2039,7 +2042,9 @@ public void performSoakTest(
int maxFailures,
int maxAcceptablePerIterationLatencyMs,
int minTimeMsBetweenRpcs,
int overallTimeoutSeconds)
int overallTimeoutSeconds,
int soakRequestSize,
int soakResponseSize)
throws Exception {
int iterationsDone = 0;
int totalFailures = 0;
Expand All @@ -2063,7 +2068,8 @@ public void performSoakTest(
.newBlockingStub(soakChannel)
.withInterceptors(recordClientCallInterceptor(clientCallCapture));
}
SoakIterationResult result = performOneSoakIteration(soakStub);
SoakIterationResult result =
performOneSoakIteration(soakStub, soakRequestSize, soakResponseSize);
SocketAddress peer = clientCallCapture
.get().getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
StringBuilder logStr = new StringBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public static void main(String[] args) throws Exception {
private int soakMinTimeMsBetweenRpcs = 0;
private int soakOverallTimeoutSeconds =
soakIterations * soakPerIterationMaxAcceptableLatencyMs / 1000;
private int soakRequestSize = 271828;
private int soakResponseSize = 314159;
private String additionalMetadata = "";
private static LoadBalancerProvider customBackendMetricsLoadBalancerProvider;

Expand Down Expand Up @@ -175,6 +177,10 @@ void parseArgs(String[] args) throws Exception {
soakMinTimeMsBetweenRpcs = Integer.parseInt(value);
} else if ("soak_overall_timeout_seconds".equals(key)) {
soakOverallTimeoutSeconds = Integer.parseInt(value);
} else if ("soak_request_size".equals(key)) {
soakRequestSize = Integer.parseInt(value);
} else if ("soak_response_size".equals(key)) {
soakResponseSize = Integer.parseInt(value);
} else if ("additional_metadata".equals(key)) {
additionalMetadata = value;
} else {
Expand Down Expand Up @@ -247,6 +253,12 @@ void parseArgs(String[] args) throws Exception {
+ "\n should stop and fail, if the desired number of "
+ "\n iterations have not yet completed. Default "
+ c.soakOverallTimeoutSeconds
+ "\n --soak_request_size "
+ "\n The request size in a soak RPC. Default "
+ c.soakRequestSize
+ "\n --soak_response_size "
+ "\n The response size in a soak RPC. Default "
+ c.soakResponseSize
+ "\n --additional_metadata "
+ "\n Additional metadata to send in each request, as a "
+ "\n semicolon-separated list of key:value pairs. Default "
Expand Down Expand Up @@ -481,7 +493,9 @@ private void runTest(TestCases testCase) throws Exception {
soakMaxFailures,
soakPerIterationMaxAcceptableLatencyMs,
soakMinTimeMsBetweenRpcs,
soakOverallTimeoutSeconds);
soakOverallTimeoutSeconds,
soakRequestSize,
soakResponseSize);
break;
}

Expand All @@ -493,7 +507,9 @@ private void runTest(TestCases testCase) throws Exception {
soakMaxFailures,
soakPerIterationMaxAcceptableLatencyMs,
soakMinTimeMsBetweenRpcs,
soakOverallTimeoutSeconds);
soakOverallTimeoutSeconds,
soakRequestSize,
soakResponseSize);
break;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public void run() {
private int soakPerIterationMaxAcceptableLatencyMs = 1000;
private int soakOverallTimeoutSeconds = 10;
private int soakMinTimeMsBetweenRpcs = 0;
private int soakRequestSize = 271828;
private int soakResponseSize = 314159;
private String testCase = "rpc_soak";
private final ArrayList<InnerClient> clients = new ArrayList<>();

Expand Down Expand Up @@ -122,6 +124,12 @@ private void parseArgs(String[] args) {
case "soak_min_time_ms_between_rpcs":
soakMinTimeMsBetweenRpcs = Integer.parseInt(value);
break;
case "soak_request_size":
soakRequestSize = Integer.parseInt(value);
break;
case "soak_response_size":
soakResponseSize = Integer.parseInt(value);
break;
default:
System.err.println("Unknown argument: " + key);
usage = true;
Expand Down Expand Up @@ -175,6 +183,14 @@ private void parseArgs(String[] args) {
+ "\n channel_soak: sends --soak_iterations RPCs, rebuilding the channel "
+ "each time."
+ "\n Default: " + c.testCase
+ "\n --soak_request_size "
+ "\n The request size in a soak RPC. Default "
+ c.soakRequestSize
+ "\n"
+ " --soak_response_size \n"
+ " The response size in a soak RPC. Default"
+ " "
+ c.soakResponseSize
);
System.exit(1);
}
Expand Down Expand Up @@ -249,7 +265,9 @@ public void run() {
soakMaxFailures,
soakPerIterationMaxAcceptableLatencyMs,
soakMinTimeMsBetweenRpcs,
soakOverallTimeoutSeconds);
soakOverallTimeoutSeconds,
soakRequestSize,
soakResponseSize);
logger.info("Test case: " + testCase + " done for server: " + serverUri);
runSucceeded = true;
} catch (Exception e) {
Expand Down

0 comments on commit cebb465

Please sign in to comment.