Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-81786

Avoid future and scheduling overhead on sync command path

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Service Arch

      Futures have a heavily optimized fast path for the case when they are already ready. It is intended to be essentially free in that case, while there is some unavoidable overhead in the case where it isn't yet ready at the time you chain additional work. This code is using a 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. Instead of doing this manually, consider just reverting this revert which reintroduced the suboptimal usage of futures here.

      This patch to SessionWorkflow::_scheduleNextIteration will bypass the scheduler overhead and keep running eager futures for sync networking:

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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());
      

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: