Skip to content

grpc: Enable shared write buffers by default#8957

Merged
arjan-bal merged 2 commits intogrpc:masterfrom
arjan-bal:enable-write-pool-by-default
Mar 9, 2026
Merged

grpc: Enable shared write buffers by default#8957
arjan-bal merged 2 commits intogrpc:masterfrom
arjan-bal:enable-write-pool-by-default

Conversation

@arjan-bal
Copy link
Copy Markdown
Contributor

@arjan-bal arjan-bal commented Mar 6, 2026

gRPC is already using pooled buffers extensively. These write buffers can hold more than 20% of the "in use" memory when using LB policies like roundrobin, least request etc. The pools help releasing the memory when a subchannel is inactive.

Benchmarks

There is no significant performance difference in the local benchmarks.

Before

go1.24.13/grpc1.80.0-dev
streaming-networkMode_Local-bufConn_true-keepalive_false-benchTime_2m0s-trace_false-latency_0s-kbps_0-MTU_0-maxConcurrentC
alls_120-reqSize_1024B-respSize_1024B-compressor_off-channelz_false-preloader_false-clientReadBufferSize_-1-clientWriteBuf
ferSize_-1-serverReadBufferSize_-1-serverWriteBufferSize_-1-sleepBetweenRPCs_0s-connections_1-recvBufferPool_simple-shared
WriteBuffer_false:
50_Latency: 344.0650µs  90_Latency: 478.0550µs  99_Latency: 884.7730µs  Avg_Latency: 354.6700µs Bytes/op: 4964.3704955955A
llocs/op: 19.35011915747468
Histogram (unit: µs)
Count: 40403676  Min:   9.7  Max: 213729.4  Avg: 354.67
------------------------------------------------------------
[        9.742000,         9.743000)         1    0.0%    0.0%  
[        9.743000,         9.750424)         0    0.0%    0.0%  
[        9.750424,         9.812970)         0    0.0%    0.0%  
[        9.812970,        10.339881)         3    0.0%    0.0%  
[       10.339881,        14.778782)      1522    0.0%    0.0%  
[       14.778782,        52.173796)     39748    0.1%    0.1%  
[       52.173796,       367.203851)  23974441   59.3%   59.4%  ######
[      367.203851,      3021.138790)  16383483   40.5%  100.0%  ####
[     3021.138790,     25378.912455)      3968    0.0%  100.0%  
[    25378.912455,    213729.439000)       509    0.0%  100.0%  
[   213729.439000,   1800467.071380)         1    0.0%  100.0%  
Number of requests:  40403676   Request throughput:  2.7582242816e+09 bit/s
Number of responses: 40403676   Response throughput: 2.7582242816e+09 bit/s

After

go1.24.13/grpc1.80.0-dev
streaming-networkMode_Local-bufConn_true-keepalive_false-benchTime_2m0s-trace_false-latency_0s-kbps_0-MTU_0-maxConcurrentC
alls_120-reqSize_1024B-respSize_1024B-compressor_off-channelz_false-preloader_false-clientReadBufferSize_-1-clientWriteBuf
ferSize_-1-serverReadBufferSize_-1-serverWriteBufferSize_-1-sleepBetweenRPCs_0s-connections_1-recvBufferPool_simple-shared
WriteBuffer_true:
50_Latency: 346.4820µs  90_Latency: 478.2350µs  99_Latency: 695.2270µs  Avg_Latency: 353.1640µs Bytes/op: 4972.45957928533
5       Allocs/op: 19.64101560175674
Histogram (unit: µs)
Count: 40619977  Min:  10.1  Max: 74013.3  Avg: 353.16
------------------------------------------------------------
[      10.103000,       10.104000)         1    0.0%    0.0%  
[      10.104000,       10.110488)         0    0.0%    0.0%  
[      10.110488,       10.159069)         2    0.0%    0.0%  
[      10.159069,       10.522840)         5    0.0%    0.0%  
[      10.522840,       13.246726)       612    0.0%    0.0%  
[      13.246726,       33.642970)     15498    0.0%    0.0%  
[      33.642970,      186.368403)   2763883    6.8%    6.8%  #
[     186.368403,     1329.964187)  37638929   92.7%   99.5%  #########
[    1329.964187,     9893.117609)    200384    0.5%  100.0%  
[    9893.117609,    74013.323000)       662    0.0%  100.0%  
[   74013.323000,   554140.273508)         1    0.0%  100.0%  
Number of requests:  40619977   Request throughput:  2.772990429866667e+09 bit/s
Number of responses: 40619977   Response throughput: 2.772990429866667e+09 bit/s

RELEASE NOTES:

@arjan-bal arjan-bal added this to the 1.80 Release milestone Mar 6, 2026
@arjan-bal arjan-bal requested a review from easwars March 6, 2026 17:25
@arjan-bal arjan-bal added Type: Performance Performance improvements (CPU, network, memory, etc) Area: Transport Includes HTTP/2 client/server and HTTP server handler transports and advanced transport features. labels Mar 6, 2026
@arjan-bal arjan-bal force-pushed the enable-write-pool-by-default branch from 6744c60 to e690776 Compare March 6, 2026 17:27
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.62%. Comparing base (b6597b3) to head (0ba7506).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8957      +/-   ##
==========================================
- Coverage   83.42%   82.62%   -0.80%     
==========================================
  Files         410      410              
  Lines       32572    32573       +1     
==========================================
- Hits        27172    26914     -258     
- Misses       4030     4065      +35     
- Partials     1370     1594     +224     
Files with missing lines Coverage Δ
dialoptions.go 87.09% <100.00%> (-1.98%) ⬇️
server.go 62.73% <ø> (-20.01%) ⬇️

... and 23 files with indirect coverage changes

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

Copy link
Copy Markdown
Contributor

@easwars easwars left a comment

Choose a reason for hiding this comment

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

Can we have a single release note that mentions the details for both client and server instead of two separate ones. Thanks.

@easwars easwars assigned arjan-bal and unassigned easwars Mar 6, 2026
@arjan-bal arjan-bal merged commit 1acfea8 into grpc:master Mar 9, 2026
15 checks passed
arjan-bal added a commit to arjan-bal/grpc-go that referenced this pull request Mar 24, 2026
gRPC is already using pooled buffers extensively. These write buffers
can hold more than 20% of the "in use" memory when using LB policies
like roundrobin, least request etc. The pools help releasing the memory
when a subchannel is inactive.

## Benchmarks

There is no significant performance difference in the local benchmarks.

Before
```
go1.24.13/grpc1.80.0-dev
streaming-networkMode_Local-bufConn_true-keepalive_false-benchTime_2m0s-trace_false-latency_0s-kbps_0-MTU_0-maxConcurrentC
alls_120-reqSize_1024B-respSize_1024B-compressor_off-channelz_false-preloader_false-clientReadBufferSize_-1-clientWriteBuf
ferSize_-1-serverReadBufferSize_-1-serverWriteBufferSize_-1-sleepBetweenRPCs_0s-connections_1-recvBufferPool_simple-shared
WriteBuffer_false:
50_Latency: 344.0650µs  90_Latency: 478.0550µs  99_Latency: 884.7730µs  Avg_Latency: 354.6700µs Bytes/op: 4964.3704955955A
llocs/op: 19.35011915747468
Histogram (unit: µs)
Count: 40403676  Min:   9.7  Max: 213729.4  Avg: 354.67
------------------------------------------------------------
[        9.742000,         9.743000)         1    0.0%    0.0%  
[        9.743000,         9.750424)         0    0.0%    0.0%  
[        9.750424,         9.812970)         0    0.0%    0.0%  
[        9.812970,        10.339881)         3    0.0%    0.0%  
[       10.339881,        14.778782)      1522    0.0%    0.0%  
[       14.778782,        52.173796)     39748    0.1%    0.1%  
[       52.173796,       367.203851)  23974441   59.3%   59.4%  ######
[      367.203851,      3021.138790)  16383483   40.5%  100.0%  ####
[     3021.138790,     25378.912455)      3968    0.0%  100.0%  
[    25378.912455,    213729.439000)       509    0.0%  100.0%  
[   213729.439000,   1800467.071380)         1    0.0%  100.0%  
Number of requests:  40403676   Request throughput:  2.7582242816e+09 bit/s
Number of responses: 40403676   Response throughput: 2.7582242816e+09 bit/s
```

After
```
go1.24.13/grpc1.80.0-dev
streaming-networkMode_Local-bufConn_true-keepalive_false-benchTime_2m0s-trace_false-latency_0s-kbps_0-MTU_0-maxConcurrentC
alls_120-reqSize_1024B-respSize_1024B-compressor_off-channelz_false-preloader_false-clientReadBufferSize_-1-clientWriteBuf
ferSize_-1-serverReadBufferSize_-1-serverWriteBufferSize_-1-sleepBetweenRPCs_0s-connections_1-recvBufferPool_simple-shared
WriteBuffer_true:
50_Latency: 346.4820µs  90_Latency: 478.2350µs  99_Latency: 695.2270µs  Avg_Latency: 353.1640µs Bytes/op: 4972.45957928533
5       Allocs/op: 19.64101560175674
Histogram (unit: µs)
Count: 40619977  Min:  10.1  Max: 74013.3  Avg: 353.16
------------------------------------------------------------
[      10.103000,       10.104000)         1    0.0%    0.0%  
[      10.104000,       10.110488)         0    0.0%    0.0%  
[      10.110488,       10.159069)         2    0.0%    0.0%  
[      10.159069,       10.522840)         5    0.0%    0.0%  
[      10.522840,       13.246726)       612    0.0%    0.0%  
[      13.246726,       33.642970)     15498    0.0%    0.0%  
[      33.642970,      186.368403)   2763883    6.8%    6.8%  #
[     186.368403,     1329.964187)  37638929   92.7%   99.5%  #########
[    1329.964187,     9893.117609)    200384    0.5%  100.0%  
[    9893.117609,    74013.323000)       662    0.0%  100.0%  
[   74013.323000,   554140.273508)         1    0.0%  100.0%  
Number of requests:  40619977   Request throughput:  2.772990429866667e+09 bit/s
Number of responses: 40619977   Response throughput: 2.772990429866667e+09 bit/s
```

RELEASE NOTES:
* grpc: Enable shared write buffers by default. Use the the
[WithSharedWriteBuffer](https://pkg.go.dev/google.golang.org/grpc#WithSharedWriteBuffer)
dial option or the
[SharedWriteBuffer](https://pkg.go.dev/google.golang.org/grpc#SharedWriteBuffer)
server option to disable it.
arjan-bal added a commit that referenced this pull request Mar 24, 2026
Original PR: #8957 

RELEASE NOTES:
* grpc: Enable shared write buffers by default. Use the
[WithSharedWriteBuffer](https://pkg.go.dev/google.golang.org/grpc#WithSharedWriteBuffer)
dial option or the
[SharedWriteBuffer](https://pkg.go.dev/google.golang.org/grpc#SharedWriteBuffer)
server option to disable it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Transport Includes HTTP/2 client/server and HTTP server handler transports and advanced transport features. Type: Performance Performance improvements (CPU, network, memory, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants