Craig Tiller | e61b7d7 | 2017-01-06 11:01:37 -0800 | [diff] [blame] | 1 | # C++ Performance Notes |
| 2 | |
| 3 | ## Streaming write buffering |
| 4 | |
| 5 | Generally, each write operation (Write(), WritesDone()) implies a syscall. |
| 6 | gRPC will try to batch together separate write operations from different |
| 7 | threads, but currently cannot automatically infer batching in a single stream. |
| 8 | |
| 9 | If message k+1 in a stream does not rely on responses from message k, it's |
| 10 | possible to enable write batching by passing a WriteOptions argument to Write |
| 11 | with the buffer_hint set: |
| 12 | |
Craig Tiller | e519a03 | 2017-01-06 12:41:21 -0800 | [diff] [blame] | 13 | ~~~{.cpp} |
Craig Tiller | e61b7d7 | 2017-01-06 11:01:37 -0800 | [diff] [blame] | 14 | stream_writer->Write(message, WriteOptions().set_buffer_hint()); |
Craig Tiller | e519a03 | 2017-01-06 12:41:21 -0800 | [diff] [blame] | 15 | ~~~ |
Craig Tiller | e61b7d7 | 2017-01-06 11:01:37 -0800 | [diff] [blame] | 16 | |
| 17 | The 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 | |
| 28 | Right now, the best performance trade-off is having numcpu's threads and one |
| 29 | completion queue per thread. |