wwbmmm commented on PR #3484:
URL: https://github.com/apache/brpc/pull/3484#issuecomment-5756087423

   > Batching changes the request execution model. The costs of this 
optimization are part of bRPC's per request isolation model.
   > 
   > Today, each parsed request runs in its own bthread. With batching enabled, 
multiple unrelated requests from the same connection run sequentially in one 
bthread. This changes observable behavior.
   > 
   > 1. User code using bthread local storage can leak state across requests in 
the same batch. In particular, 
[`brpc::thread_local_data()`](src/brpc/server.cpp:1903-1920) obtains data 
through [`bthread_getspecific()`](src/brpc/server.cpp:1913-1918). Its lifetime 
is tied to the current bthread, not to one request.
   > 2. Destructors for bthread local objects run when the bthread finishes. 
[`TaskGroup`](src/bthread/task_group.cpp:495-505) releases the key table only 
at bthread completion. With a batch, cleanup happens once per batch instead of 
once per request.
   > 3. A slow or blocking handler delays all later requests in the same batch. 
This removes the load balancing and tail latency isolation that brpc normally 
provides through independent bthreads.
   > 
   > The performance gain and the semantic change are inseparable here. 
Skipping `sched_to` and bthread local storage cleanup is exactly what creates 
the gain, but it also makes request scoped state batch scoped.
   > 
   > If the target workload really consists of tiny independent operations, 
user level request batching is a better fit. It also removes repeated RPC 
parsing, serialization, controller, tracing, and response processing costs, 
while keeping the batching semantics explicit.
   
   Agree. Besides, the rpc span feature also rely on this per-request thread 
model.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to