1# 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 13~~~{.cpp} 14stream_writer->Write(message, WriteOptions().set_buffer_hint()); 15~~~ 16 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. 30