前言
平时工作中用过dubbo和grpc, 也看过一些性能测评文章, 大致看出grpc一开始(2016年前)的性能貌似是dubbo的2/3左右
但是2017年的一篇博客看出grpc已经开始超越dubbo了,自己也一直很想亲手试试,毕竟grpc的适用场景更多,dubbo的
编码友好性更好。两个都是好的框架。
GRPC 环境
直接git clone https://github.com/grpc/grpc-java
进入里面的examples, 有
grpc-java/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java
grpc-java/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldClient.java
读里面的readme
然后改造了下 HelloWorldClient.java
/*
* Copyright 2015 The gRPC Authors
*
* Licensed 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 io.grpc.examples.helloworld;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;
import io.grpc.examples.helloworld.HelloRequest.Builder;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A simple client that requests a greeting from the {@link HelloWorldServer}.
*/
public class HelloWorldClient {
private static final Logger logger = Logger.getLogger(HelloWorldClient.class.getName());
private final ManagedChannel channel;
private final GreeterGrpc.GreeterBlockingStub blockingStub;
private final Long testScale = 1000000L;
/** Construct client connecting to HelloWorld server at {@code host:port}. */
public