#2401·roadrunner

[ CHORE]: goridge: buffer pool serves every payload from a 1 MB tier and pools oversized buffers

Author: darakanoitCreated Sep 22, 2026Updated Sep 27, 2026
LabelsC-enhancement

No duplicates .

  • I have searched for a similar issue.

What should be improved or cleaned up?

Fix: roadrunner-server/goridge#221. Follow-up to #2395.

Module is github.com/roadrunner-server/goridge/v4, internal/bpool.go on master at 826afec. Since goridge#220 this pool serves both the send and the receive path, so every request touches it twice.

The smallest tier is 1 MB. Every payload up to 1 MB, and every options read of 4 to 40 bytes, takes a 1 MB buffer while in flight:

go
func get(size uint32) *[]byte {
	switch {
	case size <= OneMB:      // a 200-byte response takes a 1 MB buffer
		val, _ := frameChunkedPool.Load(OneMB)
		return val.(*sync.Pool).Get().(*[]byte)

Resident memory grows with the number of workers, not with the size of the data. N goroutines each holding a buffer for a 200-byte payload, which is what N workers do while their responses are in flight:

workers=  8   in-flight   8.4 MB
workers= 64   in-flight  67.2 MB
workers=256   in-flight 268.7 MB

The buffers survive one GC in the victim cache, so under steady load this is permanent. A pool miss also zeroes the whole tier, 37 µs for 1 MB on an M3, which is as much as sending a 1 MB frame.

put routes by the requested size, not by the buffer. Above 10 MB get falls through to make, but put has no such branch and stores the buffer in the 10 MB tier:

go
func put(size uint32, data *[]byte) {
	switch {
	case size <= OneMB:  ...
	case size <= FiveMB: ...
	default:             // size > TenMB lands here too
		pool, _ := frameChunkedPool.Load(TenMB)
		pool.(*sync.Pool).Put(data)

Reproduction: get(50 << 20), put(50 << 20, buf), then get(6 << 20) returns a buffer with cap == 50 MB. It is handed out for every 5 to 10 MB request from then on and never released while the pool stays warm. Default max_request_size in the http plugin is 1 GB, so one large upload or response is enough to get there.

The PR adds 4 KB, 16 KB, 64 KB and 256 KB tiers below the existing ones and routes put by cap(*data), dropping anything whose capacity is not a tier size. Same rule as x/net/http2 putDataBufferChunk and grpc-go BinaryTieredBufferPool.Put. With it, 64 workers hold 0.3 MB instead of 67.2 MB, and the 1 KB send and receive paths are 20 to 25 % faster with identical allocs/op. Numbers and methodology are in the PR.

Wire format and public API are untouched, nothing in this repo changes.

Source: roadrunner-server/roadrunner