ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

基于ghz 对grpc 服务进行压测

2020-09-27 18:32:35  阅读:743  来源: 互联网

标签:int32 string proto grpc ghz 压测 bool -- message


  • 首先准备工作安装 ghz  protoc  
  • 把对应需要安装的组件添加到环境变量
  • 将执行目录转到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=10 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文件
  • 上面-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) {}
    }

     

  • 具体执行情况

     

     

标签:int32,string,proto,grpc,ghz,压测,bool,--,message
来源: https://www.cnblogs.com/chongyao/p/13741135.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有