rpc框架之 grpc vs dubbo 性能比拼

本文通过实际测试对比了grpc与dubbo的性能,早期grpc性能约为dubbo的2/3,但随着grpc的发展,现在的性能已与dubbo相当。在grpc环境中,经过改造的HelloWorldClient测试显示每秒处理7936次请求。而在dubbo环境下,测试结果显示dubbo稍快。然而,当grpc在IDE中直接启动时,性能得到提升,证明了grpc的潜力。结论是grpc虽然在速度上与dubbo接近,但其扩展性和多语言支持使其在选型上有更大优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

平时工作中用过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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值