blob: c87557558dd0fc81d2839e92312c0fc817d0f257 [file] [log] [blame] [view]
Craig Tillere61b7d72017-01-06 11:01:37 -08001# C++ Performance Notes
2
3## Streaming write buffering
4
5Generally, each write operation (Write(), WritesDone()) implies a syscall.
6gRPC will try to batch together separate write operations from different
7threads, but currently cannot automatically infer batching in a single stream.
8
9If message k+1 in a stream does not rely on responses from message k, it's
10possible to enable write batching by passing a WriteOptions argument to Write
11with the buffer_hint set:
12
Craig Tillere519a032017-01-06 12:41:21 -080013~~~{.cpp}
Craig Tillere61b7d72017-01-06 11:01:37 -080014stream_writer->Write(message, WriteOptions().set_buffer_hint());
Craig Tillere519a032017-01-06 12:41:21 -080015~~~
Craig Tillere61b7d72017-01-06 11:01:37 -080016
17The write will be buffered until one of the following is true:
18- the per-stream buffer is filled (controllable with the channel argument
19 GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE) - this prevents infinite buffering leading
20 to OOM
21- a subsequent Write without buffer_hint set is posted
22- the call is finished for writing (WritesDone() called on the client,
23 or Finish() called on an async server stream, or the service handler returns
24 for a sync server stream)
25
26## Completion Queues and Threading in the Async API
27
28Right now, the best performance trade-off is having numcpu's threads and one
29completion queue per thread.