基於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) {}
    }

     

  • 具體執行情況

     

     


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM