royguo opened a new pull request, #3168:
URL: https://github.com/apache/brpc/pull/3168

   ### What problem does this PR solve?
   
   - Implement Idle Hook: Added TaskGroup::SetWorkerIdleCallback to allow 
executing custom logic (e.g., IO polling) when a worker thread is idle.
   - Support Timeout Wait: Modified ParkingLot::wait to support an optional 
timeout, preventing workers from sleeping indefinitely when an idle callback is 
registered.
   - Enable Thread-per-Core IO: Enabled thread-local IO management (like 
io_uring ) by invoking the hook within the worker's thread context.
   - Add Unit Test: Added bthread_idle_unittest to verify worker isolation and 
idle callback execution.
   
   
   
   The main reason that we need this is that:
   1) We want to make sure all iouring cqe (or other similar async engine, 
including some network call results), can be signaled within its original task 
group (we don't want cross-thread signal, which is very slow under observation)
   2) By using a user-defined callback, we can implement the following strategy:
     - bthread submit iouriing, and tries to reap cqe result
     - if no cqe found, wait() here and next bthread will wake it up.
     - But, if the current bthread is the `last` one, then we will rely on the 
Idle Callback in the task group to wake it up.
   3) Then we will make the whole stack thread-per-core and iouring-per-thread, 
we don't need another polling thread to reap all the CQEs, which will not be 
easy to avoid cross-thread signaling.
   
   
   Issue Number: none 
   
   Problem Summary:
   
   ### What is changed and the side effects?
   
   Changed:
   - task_group.h/.cc
     - Added a new function and a few related static member variables to handle 
idle callbacks
   - parking_lot.h
     - Added a new `timeout` param to `wait()` function, with default NULL 
value, which will not break current implementation.
   
   
   Side effects:
   - Performance effects:
   No
   
   - Breaking backward compatibility: 
   NO
   
   ---
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   


-- 
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