Closed ortuman closed 7 months ago
Thanks, this is a clever idea.
To safely return body buffers back to the pool, we resorted to gRPC stats.Handler to determine whether responses have been effectively serialized and sent over the wire.
Do you have a reference for what makes this safe? E.g. is it stated in the gRPC documentation?
Do you have a reference for what makes this safe? E.g. is it stated in the gRPC documentation?
There's no explicit statement about it (haven't found it at least). However, the stats.OutPayload has two additional fields that indicate the length of the content that was sent over the wire as well as the timestamp at which the sent took place (which BTW, leads me to think that we could validate if SentTime
field is not zero before recycling the body buffer, just in case).
By my reading of the code, this only applies to server responses. Are there many cases where responses sent by httpgrpc are a sizeable portion of garbage?
Is it possible to apply the same technique to requests, on client or server side? I believe those are much more of a problem.
Signed-off-by: Miguel Ángel Ortuño ortuman@gmail.com
This PR adapts
httpgrpc
server to recycle recording buffers after they've been used for copying HTTP responses, aiming to reduce GC pressure.To safely return body buffers back to the pool, we resorted to gRPC
stats.Handler
to determine whether responses have been effectively serialized and sent over the wire.An extra benchmark named
BenchmarkServer_ServeHTTP
has been included as part of this PR to test the change.Comparision:
Here I attach the full benchmark results for the old and the new implementations.