Optimize AsyncCursor<> disposal to consume less resources

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Major - P3
    • 3.10.0
    • Affects Version/s: 3.9.0
    • Component/s: Performance
    • None
    • None
    • Fully Compatible
    • Dotnet Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Hi!

      Currently, the AsyncCursor<>.CloseIfNotAlreadyClosedFromDispose creates a CT that aborts the KillCursors after a fixed timeout. The timed CT creation is not free even in latest .NET, and for .NET Framework it's kicks very hard, because it floods the inner timer queue with requests to execute a timed callback (along with creating nontrivial amount of Gen0 garbage). For typical cursor use (reading up to a batch size of values) there is no server-side cursor to keep, so _cursorId is zero in most of the cases, so there is actually nothing to do, but the CT still gets set up on every request to the database.

      I suggest moving the _cursorId, _closed and other similar checks above the CT creation in this case – it might reduce code reuse, but will genuinely remove unnecessary pressure of several thousands of timers scheduled and un-scheduled every second when the request rate is high.

       

            Assignee:
            Oleksandr Poliakov
            Reporter:
            Aristarkh Zagorodnikov (EXT)
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: