-
Type:
Improvement
-
Resolution: Done
-
Priority:
Major - P3
-
Affects Version/s: 3.9.0
-
Component/s: Performance
-
None
-
None
-
Fully Compatible
-
Dotnet Drivers
-
Not Needed
-
-
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.