gRPC 基础使用及性能测试

2021-10-08

gRPC 是一种远程语言调用方法,解决跨语言调用问题,比 RESTFul 并发更好,速度更快,可利用 HTTP2

Python 快速开始:https://grpc.io/docs/languages/python/quickstart/

GitHub - locustio/locust: Scalable load testing tool written in Python

HTTP 负载测试工具,主要用与测试 RESTFul API,也可用于 gRPC

gRPC 测试:[https://docs.locust.io/en/stable/testing-other-systems.html?#example-writing-a-grpc-user-client](Testing other systems/protocols — Locust 2.14.0 documentation)

GitHub - bojand/ghz: Simple gRPC benchmarking and load testing tool

专门的 grpc 负载测试工具,命令行使用:Examples · ghz

1
2
3
4
5
6
7
8
9
cd grpc/example/python/helloworld
python3 greeter_server.py

ghz --insecure \\
--proto ../../protos/helloworld.proto \\
--call helloworld.Greeter.SayHello \\
-c 10 -n 2000 \\
-d '{"idx": 1}' \\
0.0.0.0:50051

实测 gRPC 与 RESTFul 最简单请求,gRPC 速度更快,除去 server 端操作,内网中,收到请求与回复请求网络延迟均在 100ms 以内,甚至 50ms 内。

两个工具对比,locust 能够自定义 client 调用参数,使用更灵活,生成报告也更丰富,能够实时查看,locust 原本是个 REST 接口测试工具,也能用于 grpc 测试;ghz 命令行使用更简单,适合简单参数的测试。

Untitled

Untitled

Untitled