zoukankan      html  css  js  c++  java
  • 基于ghz 对grpc 服务进行压测

    • 首先准备工作安装 ghz  protoc  文档具体参考 https://ghz.sh/docs/intro
    • 把对应需要安装的组件添加到环境变量
    • 将执行目录转到Protobuf 协议文件夹
      -- 首先转到proto buf 文件夹 执行命令 生成协议文件
       protoc --proto_path=. --descriptor_set_out=bundle.protoset *.proto
      -- 然后执行压测命令
       ghz --insecure --protoset ./bundle.protoset --call Jlion.NetCore.OrderService.Service.Grpc.JlionOrderService.Order_Search  -D ./Test.json -n 10000 -c 3000 --connections=2 192.168.3.10:10001
    • 参数详解
      --proto
      输入的协议缓冲区.proto文件的路径。
      --protoset
      或者,我们使用已编译的原型文件(包含由产生的已编译描述符protoc)作为输入。要创建原型文件,请protoc使用*.proto定义服务的文件进行调用。
      --call
      “ package.Service / Method”或“ package.Service.Method”格式的标准方法名称。例如:helloworld.Greeter.SayHello。
      -n 
      运行的请求总数。
      -c, --concurrency
       并发运行的请求数。请求总数不能小于并发级别。默认值为50
      --connections
      默认情况下,我们在整个测试运行中使用单个gRPC连接,并发性(-cgoroutine worker)通过共享该单个连接来实现并发 
      -d, --data
      呼叫数据为字符串化JSON。如果值为,@则从标准输入(stdin)中读取请求内容。范例:-d '{"name":"Bob"}'。
      -D
      为入参Json文件
      192.168.3.10:10001
      为需要压测的服务地址+端口
      --insecure
      Use plaintext and insecure connection.
    • 上面-D参数 入参的Test.json 文件
      {"OrderId":"Joe","Name":"test"}
    • 协议文件具体
      syntax = "proto3";
      package Jlion.NetCore.OrderService.Service.Grpc;
      
      message BoolResponse {
          bool Success = 1;
          string ErrorMsg = 2;
      }
      
      enum EnumSortType {
          UnknownSortType = 0;
          Asc = 1;
          Desc = 2;
      }
      
      message UserSearchRequest{
          bool IsMaster = 1;
          int32 Page = 2;
          int32 Rows = 3;
          bool ReturnTotal = 4;
          EnumSortType SortType = 5;
          string SortField = 6;
          int32 UserId = 7; 
          string UserName = 8;
          int32  MerchantId = 9;
      }
      
      message UserRequest{
          int32 UserId = 1;
          int32 MerchantId = 2;
          string UserName = 3;
          string RealName = 4;
          string Password = 5;
      }
       
      message UserByIdRequest{
          bool IsMaster = 1;
          int32 MerchantId = 2;
          int32 UserId =  3;
      }
      
      message UserSearchResponse{
          bool Success = 1;
          string ErrorMsg = 2;
          repeated UserResponse Data = 3;
           int32 TotalCount = 4;
      }
      
      message UserResponse{
          int32 UserId = 1;
          int32 MerchantId = 2;
          string UserName = 3;
          string RealName = 4;
          string AddTime=5;
      }
      
      message OrderSearchRequest{
          string OrderId = 1; //定义订单ID
          string Name = 2;
      }
      
      message OrderRepsonse{
          string OrderId = 1;
          string Name = 2;
          double Amount = 3;
          int32 Count = 4;
          string Time = 5;
      }
      
      message OrderSearchResponse{
          bool Success = 1;
          string ErrorMsg = 2;
          repeated OrderRepsonse Data = 3;
      }
      
      
      service JlionOrderService{
          rpc Order_Search(OrderSearchRequest) returns (OrderSearchResponse){} 
      
          rpc Order_Create(OrderRepsonse) returns (BoolResponse) {}
      
          rpc Create_User(UserRequest) returns (BoolResponse) {} 
      
          rpc GetById_User(UserByIdRequest) returns (UserResponse) {} 
      
          rpc User_Search(UserSearchRequest) returns (UserSearchResponse) {}
      }
    • 具体执行情况
  • 相关阅读:
    正则表达式
    前端开发工程师
    前端开发工程师
    Java开发工程师(Web方向)
    Java开发工程师(Web方向)
    Java开发工程师(Web方向)
    Java开发工程师(Web方向)
    Java开发工程师(Web方向)
    前端开发工程师
    前端开发工程师
  • 原文地址:https://www.cnblogs.com/chongyao/p/13741135.html
Copyright © 2011-2022 走看看