You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
transport: Reduce pointer usage in Stream structs (#8624)
The pprof profiles for unary RPC benchmarks indicate significant time
spent in `runtime.mallocgc` and `runtime.gcBgMarkWorker`. This indicates
gRPC is spending significant CPU cycles allocating or garbage
collecting.
This change reduces the number of pointer fields in the structs that
represent client and server stream. This will reduce number of memory
allocations (faster) and also reduce pressure on garbage collector
(faster garbage collections) since the GC doesn't need to scan
non-pointer fields. For structs which were stored as pointers to ensure
values are not copied, a `noCopy` struct is embedded that will cause `go
vet` to fail if copies are performed. Non-pointer fields are also moved
to the end of the struct to improve allocation speed.
## Results
There are improvements in QPS, latency and allocs/op for unary RPCs.
```sh
# test command
go run benchmark/benchmain/main.go -benchtime=60s -workloads=unary \
-compression=off -maxConcurrentCalls=500 -trace=off \
-reqSizeBytes=100 -respSizeBytes=100 -networkMode=Local -resultFile="${RUN_NAME}" -recvBufferPool=simple
go run benchmark/benchresult/main.go unary-before unary-after
Title Before After Percentage
TotalOps 7690250 7991877 3.92%
SendOps 0 0 NaN%
RecvOps 0 0 NaN%
Bytes/op 10218.14 10084.00 -1.31%
Allocs/op 164.85 151.85 -7.89%
ReqT/op 102536666.67 106558360.00 3.92%
RespT/op 102536666.67 106558360.00 3.92%
50th-Lat 3.57283ms 3.435143ms -3.85%
90th-Lat 5.152403ms 4.979906ms -3.35%
99th-Lat 5.985282ms 5.827893ms -2.63%
Avg-Lat 3.89872ms 3.750449ms -3.80%
GoVersion go1.24.4 go1.24.4
GrpcVersion 1.77.0-dev 1.77.0-dev
```
## Resources
*
go/go/performance?polyglot=open-source#application-spends-too-much-on-gc-or-allocations
* go/go/performance?polyglot=open-source#memory-optimizations
RELEASE NOTES:
* transport: Reduce pointer usage to lower garbage collection pressure
and improve unary RPC performance.
0 commit comments