From f22e43e4f3f84e56f92ca5b33a0488705c225ec0 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 29 Jun 2023 11:25:58 -0500 Subject: [PATCH] Enable net6.0 build This allows for using new APIs introduced in net6.0. In order to enable building for net6.0, we also need to revert the thread pool changes in #1939 and #1950. This was already effectively reverted in #1992 by not building for net6.0. Now that we are building for net6.0 again, these if-defs need to be removed. --- .../ConnectionMultiplexer.ReaderWriter.cs | 20 ++----------------- src/StackExchange.Redis/PhysicalBridge.cs | 5 ----- .../StackExchange.Redis.csproj | 5 ++--- .../StackExchange.Redis.Tests/ConfigTests.cs | 2 +- 4 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/StackExchange.Redis/ConnectionMultiplexer.ReaderWriter.cs b/src/StackExchange.Redis/ConnectionMultiplexer.ReaderWriter.cs index b9ae3a15a..a30da7865 100644 --- a/src/StackExchange.Redis/ConnectionMultiplexer.ReaderWriter.cs +++ b/src/StackExchange.Redis/ConnectionMultiplexer.ReaderWriter.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace StackExchange.Redis; @@ -9,27 +9,11 @@ public partial class ConnectionMultiplexer [MemberNotNull(nameof(SocketManager))] private void OnCreateReaderWriter(ConfigurationOptions configuration) { - SocketManager = configuration.SocketManager ?? GetDefaultSocketManager(); + SocketManager = configuration.SocketManager ?? SocketManager.Shared; } private void OnCloseReaderWriter() { SocketManager = null; } - - /// - /// .NET 6.0+ has changes to sync-over-async stalls in the .NET primary thread pool - /// If we're in that environment, by default remove the overhead of our own threadpool - /// This will eliminate some context-switching overhead and better-size threads on both large - /// and small environments, from 16 core machines to single core VMs where the default 10 threads - /// isn't an ideal situation. - /// - internal static SocketManager GetDefaultSocketManager() - { -#if NET6_0_OR_GREATER - return SocketManager.ThreadPool; -#else - return SocketManager.Shared; -#endif - } } diff --git a/src/StackExchange.Redis/PhysicalBridge.cs b/src/StackExchange.Redis/PhysicalBridge.cs index b42c40a19..f211cae61 100644 --- a/src/StackExchange.Redis/PhysicalBridge.cs +++ b/src/StackExchange.Redis/PhysicalBridge.cs @@ -855,10 +855,6 @@ private void StartBacklogProcessor() { _backlogStatus = BacklogStatus.Activating; -#if NET6_0_OR_GREATER - // In .NET 6, use the thread pool stall semantics to our advantage and use a lighter-weight Task - Task.Run(ProcessBacklogAsync); -#else // Start the backlog processor; this is a bit unorthodox, as you would *expect* this to just // be Task.Run; that would work fine when healthy, but when we're falling on our face, it is // easy to get into a thread-pool-starvation "spiral of death" if we rely on the thread-pool @@ -871,7 +867,6 @@ private void StartBacklogProcessor() Name = "StackExchange.Redis Backlog", // help anyone looking at thread-dumps }; thread.Start(this); -#endif } else { diff --git a/src/StackExchange.Redis/StackExchange.Redis.csproj b/src/StackExchange.Redis/StackExchange.Redis.csproj index 4a8b28f92..01613419d 100644 --- a/src/StackExchange.Redis/StackExchange.Redis.csproj +++ b/src/StackExchange.Redis/StackExchange.Redis.csproj @@ -2,8 +2,7 @@ enable - - net461;netstandard2.0;net472;netcoreapp3.1;net5.0 + net461;netstandard2.0;net472;netcoreapp3.1;net5.0;net6.0 High performance Redis client, incorporating both synchronous and asynchronous usage. StackExchange.Redis StackExchange.Redis @@ -35,7 +34,7 @@ - + diff --git a/tests/StackExchange.Redis.Tests/ConfigTests.cs b/tests/StackExchange.Redis.Tests/ConfigTests.cs index b11c968cf..f5a2764c7 100644 --- a/tests/StackExchange.Redis.Tests/ConfigTests.cs +++ b/tests/StackExchange.Redis.Tests/ConfigTests.cs @@ -468,7 +468,7 @@ public void DefaultThreadPoolManagerIsDetected() using var conn = ConnectionMultiplexer.Connect(config); - Assert.Same(ConnectionMultiplexer.GetDefaultSocketManager().Scheduler, conn.SocketManager?.Scheduler); + Assert.Same(SocketManager.Shared.Scheduler, conn.SocketManager?.Scheduler); } [Theory]