Skip to content

Commit

Permalink
dump memory
Browse files Browse the repository at this point in the history
  • Loading branch information
YifeiZhuang committed Jan 25, 2024
1 parent 8ea3355 commit 983468d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.OutputTimeUnit;
Expand Down Expand Up @@ -201,7 +202,7 @@ public SimpleResponse unaryCall1024Latency() {
return stub.unaryCall(UNARY_CALL_1024_REQUEST);
}

private static final int BYTE_THROUGHPUT_RESPONSE_SIZE = 1048576;
private static final int BYTE_THROUGHPUT_RESPONSE_SIZE = 4194100;
private static final SimpleRequest BYTE_THROUGHPUT_REQUEST = SimpleRequest.newBuilder()
.setResponseSize(BYTE_THROUGHPUT_RESPONSE_SIZE)
.build();
Expand All @@ -224,6 +225,8 @@ public static class PingPongStreamState {
private SimpleResponse response;
private Throwable status;

int iteration = 0;

@Setup
public void setUp(TransportBenchmark bench) {
requestObserver = bench.asyncStub
Expand All @@ -246,6 +249,13 @@ public void setUp(TransportBenchmark bench) {

/** Issues request and waits for response. */
public SimpleResponse pingPong(SimpleRequest request) throws InterruptedException {
if (iteration++ % 200 == 0) {
Runtime runtime = Runtime.getRuntime();
System.out.println("Total memory " + runtime.totalMemory() / (1024 * 1024) +
" Free memory " + runtime.freeMemory() / (1024 * 1024) +
" Used memory " + (runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024)
);
}
requestObserver.onNext(request);
while (true) {
executor.waitAndDrain();
Expand Down Expand Up @@ -275,7 +285,8 @@ public void tearDown() throws InterruptedException {
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OperationsPerInvocation(BYTE_THROUGHPUT_RESPONSE_SIZE)
@Threads(10)
@Threads(1)
@Measurement(iterations = 1, time = 60, timeUnit = TimeUnit.SECONDS)
public SimpleResponse streamingCallsByteThroughput(PingPongStreamState state)
throws InterruptedException {
return state.pingPong(BYTE_THROUGHPUT_REQUEST);
Expand Down

0 comments on commit 983468d

Please sign in to comment.