[SERVER-81785] Avoid future and scheduling overhead on sync command path Created: 03/Oct/23  Updated: 31/Jan/24  Resolved: 31/Jan/24

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.3.0-rc2

Type: Improvement Priority: Major - P3
Reporter: Mathias Stearn Assignee: Alex Li
Resolution: Fixed Votes: 0
Labels: perf-8.0, perf-tiger, perf-tiger-handoff, perf-tiger-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-81786 Avoid future and scheduling overhead ... Closed
Related
related to SERVER-82831 De-futurize the command path In Progress
Assigned Teams:
Service Arch
Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2023-12-11, Service Arch 2023-12-25, Service Arch 2024-01-08, Service Arch 2024-01-22, Service Arch 2024-02-05
Participants:

 Description   

Futures are heavily optimized to be essentially free in the "ready already" case, but do have some overhead when chaining on a non-ready future. This code is using the slower "not-ready-yet" path for futures, even though it triggers the chain before returning. Defuturizing or at least using makeReadyFutureWith() should be an easy win. Consider reverting this revert which reintroduced the usage of the slow path in this code.

Additionally, this patch to SessionWorkflow::_scheduleNextIteration will bypass the scheduler overhead and keep running eager futures in an ordinary loop when doing sync networking.

diff --git a/src/mongo/transport/session_workflow.cpp b/src/mongo/transport/session_workflow.cpp
index 7342a707866..3ddc787deff 100644
--- a/src/mongo/transport/session_workflow.cpp
+++ b/src/mongo/transport/session_workflow.cpp
@@ -809,7 +809,10 @@ void SessionWorkflow::Impl::_scheduleIteration() try {
         }
         if (useDedicatedThread()) {
             try {
-                _doOneIteration().get();
+                while (useDedicatedThread()) {
+                    _doOneIteration().get();
+                    _work = nullptr;
+                }
                 _scheduleIteration();
             } catch (const DBException& ex) {
                 _onLoopError(ex.toStatus());

These combine to a small 2-3% improvement, which is small and hard to measure, but can be combined with other small wins to add up to something substantial. This also seems to be the "obviously better" thing to do, so there shouldn't be any controversy on this case.



 Comments   
Comment by Githook User [ 31/Jan/24 ]

Author:

{'name': 'Alex Li', 'email': '98560274+lia394126@users.noreply.github.com', 'username': 'lia394126'}

Message: SERVER-81785 Avoid future and scheduling overhead on sync command path (#18501)

GitOrigin-RevId: 998fb0c4575cbe5782923bc6962947cc915dec70
Branch: master
https://github.com/mongodb/mongo/commit/f18e5156fe3a743eb1ae8234038b0528e14347af

Generated at Thu Feb 08 06:47:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.