Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug preventing batching of writes #1256

Closed
MakMukhi opened this issue May 23, 2017 · 2 comments
Closed

Bug preventing batching of writes #1256

MakMukhi opened this issue May 23, 2017 · 2 comments
Assignees
Labels
Type: Performance Performance improvements (CPU, network, memory, etc)

Comments

@MakMukhi
Copy link
Contributor

Write() method in both http2_client and http2_server writes data out in 16K chunks but for every chunk does a force flush. This seems to be an oversight. Removing it will save us a lot of flush system calls.
https://github.com/grpc/grpc-go/blob/master/transport/http2_client.go#L785

We should write some tests with a multiple connections to a server with multiple streams. This will ensure help us be sure that this and future such optimizations don't put the code in a bad state.

@petermattis
Copy link
Contributor

Related, I noticed today that the gRPC flushing behavior when responding to a unary RPC creates 3 packets where it seems only 1 is necessary. These 3 packets are created by 3 separate flushes in the grpc.Server.processUnaryRPC path:

  1. http2Server.Write calls http2Server.writeHeaders which always forces a flush after writing the header.
  2. http2Server.Write specifies forceFlush=true on the last call to writeData and it also directly calls flushWrite if this is the last writer.
  3. Server.processUnaryRPC calls http2Server.WriteStatus which calls writeHeaders and forces a flush.

Given that a unary RPC will always call WriteStatus, can we eliminate the forced flushes in http2Server.Write? I hacked something up to do this, and it reduced 99%-tile latencies in a simple test harness from 1.9ms to 1.1ms and 95%-tile latencies from 1.3ms to 0.9ms.

petermattis added a commit to petermattis/grpc-go that referenced this issue Jul 15, 2017
This reduces the number of packets sent when responding to a unary RPC
from 3 to 1. This reduction in packets improves latency, presumably by
the lower syscall and packet overhead.

See grpc#1256
@MakMukhi MakMukhi added the Type: Performance Performance improvements (CPU, network, memory, etc) label Aug 22, 2017
@dfawley
Copy link
Member

dfawley commented Oct 19, 2017

This was fixed by #1498

@dfawley dfawley closed this as completed Oct 19, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Performance Performance improvements (CPU, network, memory, etc)
Projects
None yet
Development

No branches or pull requests

4 participants