Search in sources :

Example 1 with BenchmarkServiceStub

use of io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub in project grpc-java by grpc.

the class AsyncClient method doUnaryCalls.

private Future<Histogram> doUnaryCalls(Channel channel, final SimpleRequest request, final long endTime) {
    final BenchmarkServiceStub stub = BenchmarkServiceGrpc.newStub(channel);
    final Histogram histogram = new Histogram(HISTOGRAM_MAX_VALUE, HISTOGRAM_PRECISION);
    final HistogramFuture future = new HistogramFuture(histogram);
    stub.unaryCall(request, new StreamObserver<SimpleResponse>() {

        long lastCall = System.nanoTime();

        @Override
        public void onNext(SimpleResponse value) {
        }

        @Override
        public void onError(Throwable t) {
            Status status = Status.fromThrowable(t);
            System.err.println("Encountered an error in unaryCall. Status is " + status);
            t.printStackTrace();
            future.cancel(true);
        }

        @Override
        public void onCompleted() {
            long now = System.nanoTime();
            // Record the latencies in microseconds
            histogram.recordValue((now - lastCall) / 1000);
            lastCall = now;
            if (endTime > now) {
                stub.unaryCall(request, this);
            } else {
                future.done();
            }
        }
    });
    return future;
}
Also used : Status(io.grpc.Status) Utils.saveHistogram(io.grpc.benchmarks.Utils.saveHistogram) Histogram(org.HdrHistogram.Histogram) SimpleResponse(io.grpc.benchmarks.proto.Messages.SimpleResponse) BenchmarkServiceStub(io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub)

Example 2 with BenchmarkServiceStub

use of io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub in project grpc-java by grpc.

the class AsyncClient method doStreamingCalls.

private static Future<Histogram> doStreamingCalls(Channel channel, final SimpleRequest request, final long endTime) {
    final BenchmarkServiceStub stub = BenchmarkServiceGrpc.newStub(channel);
    final Histogram histogram = new Histogram(HISTOGRAM_MAX_VALUE, HISTOGRAM_PRECISION);
    final HistogramFuture future = new HistogramFuture(histogram);
    ThisIsAHackStreamObserver responseObserver = new ThisIsAHackStreamObserver(request, histogram, future, endTime);
    StreamObserver<SimpleRequest> requestObserver = stub.streamingCall(responseObserver);
    responseObserver.requestObserver = requestObserver;
    requestObserver.onNext(request);
    return future;
}
Also used : Utils.saveHistogram(io.grpc.benchmarks.Utils.saveHistogram) Histogram(org.HdrHistogram.Histogram) SimpleRequest(io.grpc.benchmarks.proto.Messages.SimpleRequest) BenchmarkServiceStub(io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub)

Aggregations

Utils.saveHistogram (io.grpc.benchmarks.Utils.saveHistogram)2 BenchmarkServiceStub (io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub)2 Histogram (org.HdrHistogram.Histogram)2 Status (io.grpc.Status)1 SimpleRequest (io.grpc.benchmarks.proto.Messages.SimpleRequest)1 SimpleResponse (io.grpc.benchmarks.proto.Messages.SimpleResponse)1