Skip to content

benchmark: add README documenting how to run benchmarks (#8574)#9144

Open
luongs3 wants to merge 1 commit into
grpc:masterfrom
luongs3:docs/8574-benchmark-readme
Open

benchmark: add README documenting how to run benchmarks (#8574)#9144
luongs3 wants to merge 1 commit into
grpc:masterfrom
luongs3:docs/8574-benchmark-readme

Conversation

@luongs3

@luongs3 luongs3 commented May 27, 2026

Copy link
Copy Markdown

Fixes #8574.

Adds a README.md to the benchmark/ directory documenting the commonly used ways to run the benchmarks, and links to it from CONTRIBUTING.md.

What's covered

  • benchmain — the primary configurable driver, with the canonical example invocation (mirrors the package doc in benchmark/benchmain/main.go) and the recommended baseline-capture-then-compare workflow using benchresult.
  • run_bench.sh — the shell harness that sweeps parameter combinations.
  • Go micro-benchmarksgo test -bench for packages like primitives and latency.
  • A directory overview table so readers can find the right entry point.

The CONTRIBUTING.md link is added under the testing bullet in "Guidelines for Pull Requests", so authors and reviewers can find it when a performance-focused PR needs benchmark results — which is the motivation in the issue.

Verification

The documented commands were run against the current tree:

  • go run benchmark/benchmain/main.go -h lists the flags.
  • go test -bench=BenchmarkCodeStringSwitch -benchmem -run='^$' ./benchmark/primitives/ runs and passes.

No code changes; docs only.

RELEASE NOTES: n/a

Adds benchmark/README.md covering the common ways to run the benchmarks:
the benchmain driver and baseline comparison via benchresult, the
run_bench.sh parameter sweep, and the go test -bench micro-benchmarks,
plus a directory overview. Links to it from CONTRIBUTING.md so authors and
reviewers can find it when a performance PR needs benchmark results.

Fixes grpc#8574.

RELEASE NOTES: n/a
@linux-foundation-easycla

linux-foundation-easycla Bot commented May 27, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: luongs3 / name: luongs3 (0acd88a)

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.09%. Comparing base (18a8d3d) to head (0acd88a).
⚠️ Report is 30 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9144      +/-   ##
==========================================
- Coverage   83.16%   83.09%   -0.07%     
==========================================
  Files         417      417              
  Lines       33690    33690              
==========================================
- Hits        28019    27996      -23     
- Misses       4253     4268      +15     
- Partials     1418     1426       +8     

see 26 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@easwars

easwars commented May 27, 2026

Copy link
Copy Markdown
Contributor

@luongs3: Could you please sign the CLA for us to start reviewing the changes.

@easwars easwars added Status: Requires Reporter Clarification Area: Benchmarking Includes our benchmarking utility. Type: Documentation Documentation or examples labels May 27, 2026
@easwars easwars added this to the 1.82 Release milestone May 27, 2026
@easwars easwars assigned mbissa and unassigned luongs3 Jun 3, 2026
@mbissa mbissa modified the milestones: 1.82 Release, 1.83 Release Jun 5, 2026
@mbissa

mbissa commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds documentation for running benchmarks in gRPC-Go, updating CONTRIBUTING.md to reference the benchmark guidelines and creating a new benchmark/README.md file that explains how to use the benchmain driver, run_bench.sh harness, and Go micro-benchmarks. The review feedback correctly points out that because the benchmark directory is a separate Go module, running the documented commands from the repository root will result in a Go module error. The reviewer suggests adding instructions to change the working directory to benchmark/ first and updating all example commands to remove the benchmark/ prefix accordingly.

Comment thread benchmark/README.md
Comment on lines +13 to +16
`benchmark/benchmain/main.go` runs configurable client/server workloads and
writes a result file you can format and diff.

Run a set of workloads with profiling enabled:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since benchmark is a separate Go module (it has its own go.mod), running go run or go test commands targeting the benchmark directory from the repository root will fail with a Go module error:

go: directory benchmark/... is contained in a module that is not the main module

It is highly recommended to instruct users to first change their working directory to benchmark/ before running any commands.

Consider adding a note like this:

First, change your working directory to the `benchmark` directory:

```sh
cd benchmark

Comment thread benchmark/README.md
Comment on lines +19 to +22
go run benchmark/benchmain/main.go -benchtime=10s -workloads=all \
-compression=gzip -maxConcurrentCalls=1 -trace=off \
-reqSizeBytes=1,1048576 -respSizeBytes=1,1048576 -networkMode=Local \
-cpuProfile=cpuProf -memProfile=memProf -memProfileRate=10000 -resultFile=result

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the benchmark/ prefix from the path to main.go to align with running the commands from within the benchmark directory.

Suggested change
go run benchmark/benchmain/main.go -benchtime=10s -workloads=all \
-compression=gzip -maxConcurrentCalls=1 -trace=off \
-reqSizeBytes=1,1048576 -respSizeBytes=1,1048576 -networkMode=Local \
-cpuProfile=cpuProf -memProfile=memProf -memProfileRate=10000 -resultFile=result
go run benchmain/main.go -benchtime=10s -workloads=all \
-compression=gzip -maxConcurrentCalls=1 -trace=off \
-reqSizeBytes=1,1048576 -respSizeBytes=1,1048576 -networkMode=Local \
-cpuProfile=cpuProf -memProfile=memProf -memProfileRate=10000 -resultFile=result

Comment thread benchmark/README.md
Pass `-h` to see all available flags:

```sh
go run benchmark/benchmain/main.go -h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the benchmark/ prefix since the command should be run from within the benchmark directory.

Suggested change
go run benchmark/benchmain/main.go -h
go run benchmain/main.go -h

Comment thread benchmark/README.md
Comment on lines +38 to +41
go run benchmark/benchmain/main.go -benchtime=10s -workloads=all -resultFile=basePerf

# After your change, capture the current result:
go run benchmark/benchmain/main.go -benchtime=10s -workloads=all -resultFile=curPerf

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the benchmark/ prefix from the paths to main.go to align with running the commands from within the benchmark directory.

Suggested change
go run benchmark/benchmain/main.go -benchtime=10s -workloads=all -resultFile=basePerf
# After your change, capture the current result:
go run benchmark/benchmain/main.go -benchtime=10s -workloads=all -resultFile=curPerf
go run benchmain/main.go -benchtime=10s -workloads=all -resultFile=basePerf
# After your change, capture the current result:
go run benchmain/main.go -benchtime=10s -workloads=all -resultFile=curPerf

Comment thread benchmark/README.md
Comment on lines +48 to +51
go run benchmark/benchresult/main.go curPerf

# Compare two result files (prints the change for benchmarks present in both):
go run benchmark/benchresult/main.go basePerf curPerf

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the benchmark/ prefix from the paths to benchresult/main.go to align with running the commands from within the benchmark directory.

Suggested change
go run benchmark/benchresult/main.go curPerf
# Compare two result files (prints the change for benchmarks present in both):
go run benchmark/benchresult/main.go basePerf curPerf
go run benchresult/main.go curPerf
# Compare two result files (prints the change for benchmarks present in both):
go run benchresult/main.go basePerf curPerf

Comment thread benchmark/README.md
comma-separated list of values, and the script runs every combination.

```sh
./benchmark/run_bench.sh -r 1,10 -c 1,10 -req 1,1024 -resp 1,1024 -rpc_type unary,streaming

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the benchmark/ prefix from the path to run_bench.sh to align with running the commands from within the benchmark directory.

Suggested change
./benchmark/run_bench.sh -r 1,10 -c 1,10 -req 1,1024 -resp 1,1024 -rpc_type unary,streaming
./run_bench.sh -r 1,10 -c 1,10 -req 1,1024 -resp 1,1024 -rpc_type unary,streaming

Comment thread benchmark/README.md
Comment on lines +75 to +78
go test -bench=. -benchmem ./benchmark/primitives/

# Run a single benchmark:
go test -bench=BenchmarkCodeStringSwitch -benchmem ./benchmark/primitives/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the benchmark/ prefix from the package paths to align with running the commands from within the benchmark directory.

Suggested change
go test -bench=. -benchmem ./benchmark/primitives/
# Run a single benchmark:
go test -bench=BenchmarkCodeStringSwitch -benchmem ./benchmark/primitives/
go test -bench=. -benchmem ./primitives/
# Run a single benchmark:
go test -bench=BenchmarkCodeStringSwitch -benchmem ./primitives/

@mbissa

mbissa commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@luongs3 Thanks a lot for this contribution. Apologies for the delay in responding. Can you have a look at the comments once and address them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Benchmarking Includes our benchmarking utility. Status: Requires Reporter Clarification Type: Documentation Documentation or examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a README to the benchmark directory

3 participants