v2.5 Backlog: Use AutoResetEvent for backlog thread lingering by NickCraver · Pull Request #2008 · StackExchange/StackExchange.Redis

@NickCraver

This prevents so many threads from starting/stopping as we finish flushing a backlog.

@NickCraver NickCraver changed the title v2.5 Backlog: Use Autoreset for backlog thread lingering v2.5 Backlog: Use AutoResetEvent for backlog thread lingering

Feb 24, 2022

@NickCraver

mgravell

philon-msft

kevin-montrose

NickCraver added a commit that referenced this pull request

Feb 24, 2022
A few tweaks to the changes #2008 for disposing and normalization.

NickCraver added a commit that referenced this pull request

Feb 24, 2022
A few tweaks to the changes #2008 for disposing and normalization.

NickCraver added a commit that referenced this pull request

Feb 26, 2022
Alrighty, #2008 did something exceedingly stupid: it lingered *inside the lock*, jamming the connection and backlog during linger. Instead, this moves the thread preservation up in a much cleaner way and doesn't occupy the lock.

Also adds a SpinningDown status so we can see it proper in exceptions, always.

NickCraver added a commit that referenced this pull request

Feb 26, 2022
In troubleshooting these 2 tests, I realized what's happening: a really dumb placement mistake in #2008. Now, instead of locking inside the damn lock, it loops outside a bit cleaner and higher up. Performance wins are the same but it's a lot sander and doesn't block both the backlog and the writer for another 5 seconds. Now only the thread lingers and it'll try to get the lock when running another pass, if it gets any in the next 5 seconds.