Search in sources :

Example 1 with SimpleResponse

use of io.grpc.benchmarks.proto.Messages.SimpleResponse 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)

Aggregations

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