anushkagupta200615-jpg opened a new pull request, #16370:
URL: https://github.com/apache/dubbo/pull/16370

   ## What is the purpose of the change?
   
   Fixes #16174
   
   This PR addresses the benchmark methodology issue and the root cause of the 
`VirtualThreadPool` configuration bug introduced in #16055.
   
   **Problem:**
   1. **Broken `keepAliveTime`:** The pooled virtual thread implementation used 
`keepAliveTime = 0L MILLISECONDS`. Because of this, non-core threads died 
immediately after completing a task. This defeated the entire purpose of the 
pooled mode (as outlined in #16042), which is to keep threads warm so that 
libraries like FastJSON and Aerospike can reuse their heavy `ThreadLocal` byte 
buffers across requests.
   2. **Flawed Benchmark:** The benchmark in the original PR used a flawed 
two-latch synchronization pattern. It awaited the `startGate` (which was 
already zero) instead of the `completionLatch`. As a result, the timing window 
closed *before* the tasks were actually completed, masking the `keepAlive` 
overhead and falsely inflating the performance metrics of the pooled executor.
   
   **Solution:**
   - **Fixed `keepAliveTime`:** Updated `VirtualThreadPool` to use `60L 
SECONDS` for `keepAliveTime` in the pooled branch. This ensures warm virtual 
threads survive long enough to reuse their `ThreadLocal` caches between 
subsequent requests.
   - **Added Regression Guards:** Enhanced `VirtualThreadPoolTest` to verify 
that `keepAliveTime > 0` and added a test 
`getExecutor4_threadLocalReuseInPooledMode` proving that `ThreadLocal` state is 
actually preserved and reused across sequential tasks on the pooled executor.
   - **Added Correct Benchmark Test:** Introduced 
`VirtualThreadPoolBenchmarkTest.java` that uses the correct two-latch pattern 
(awaiting the completion latch) to strictly verify that all submitted tasks run 
to completion within the benchmark window for both pooled and unpooled modes.
   
   ## Checklist
   - [x] Make sure there is a 
[GitHub_issue](https://github.com/apache/dubbo/issues) field for the change.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Write necessary unit-test to verify your logic correction. If the new 
feature or significant change is committed, please remember to add sample in 
[dubbo samples](https://github.com/apache/dubbo-samples) project.
   - [x] Make sure gitHub actions can pass. [Why the workflow is failing and 
how to fix it?](../CONTRIBUTING.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