github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/grpc/Documentation/benchmark.md (about)

     1  # Benchmark
     2  
     3  gRPC-Go comes with a set of benchmarking utilities to measure performance.
     4  These utilities can be found in the `benchmark` directory within the project's
     5  root directory.
     6  
     7  The main utility, aptly named `benchmain`, supports a host of configurable
     8  parameters to simulate various environments and workloads. For example, if your
     9  server's workload is primarily streaming RPCs with large messages with
    10  compression turned on, invoking `benchmain` in the following way may closely
    11  simulate your application:
    12  
    13  ```bash
    14  $ go run google.golang.org/grpc/benchmark/benchmain/main.go \
    15      -workloads=streaming \
    16    	-reqSizeBytes=1024 \
    17    	-respSizeBytes=1024 \
    18    	-compression=gzip
    19  ```
    20  
    21  Pass the `-h` flag to the `benchmain` utility to see other flags and workloads
    22  that are supported.
    23  
    24  ## Varying Payload Sizes (Weighted Random Distribution)
    25  
    26  The `benchmain` utility supports two flags, `-reqPayloadCurveFiles` and
    27  `-respPayloadCurveFiles`, that can be used to specify a histograms representing
    28  a weighted random distribution of request and response payload sizes,
    29  respectively. This is useful to simulate workloads with arbitrary payload
    30  sizes.
    31  
    32  The options takes a comma-separated list of file paths as value. Each file must
    33  be a valid CSV file with three columns in each row. Each row represents a range
    34  of payload sizes (first two columns) and the weight associated with that range
    35  (third column). For example, consider the below file:
    36  
    37  ```csv
    38  1,32,12.5
    39  128,256,12.5
    40  1024,2048,25.0
    41  ```
    42  
    43  Assume that `benchmain` is invoked like so:
    44  
    45  ```bash
    46  $ go run google.golang.org/grpc/benchmark/benchmain/main.go \
    47      -workloads=unary \
    48    	-reqPayloadCurveFiles=/path/to/csv \
    49    	-respPayloadCurveFiles=/path/to/csv
    50  ```
    51  
    52  This tells the `benchmain` utility to generate unary RPC requests with a 25%
    53  probability of payload sizes in the ranges 1-32 bytes, 25% probability in the
    54  128-256 bytes range, and 50% probability in the 1024-2048 bytes range. RPC
    55  requests outside these ranges will not be generated.
    56  
    57  You may specify multiple CSV files delimited by a comma. The utility will
    58  execute the benchmark with each combination independently. That is, the
    59  following command will execute four benchmarks:
    60  
    61  ```bash
    62  $ go run google.golang.org/grpc/benchmark/benchmain/main.go \
    63      -workloads=unary \
    64    	-reqPayloadCurveFiles=/path/to/csv1,/path/to/csv2 \
    65    	-respPayloadCurveFiles=/path/to/csv3,/path/to/csv4
    66  ```
    67  
    68  You may also combine `PayloadCurveFiles` with `SizeBytes` options. For example:
    69  
    70  ```
    71  $ go run google.golang.org/grpc/benchmark/benchmain/main.go \
    72      -workloads=unary \
    73    	-reqPayloadCurveFiles=/path/to/csv \
    74    	-respSizeBytes=1
    75  ```