Skip to content

Commit

Permalink
Enable net6.0 build
Browse files Browse the repository at this point in the history
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 StackExchange#1939 and StackExchange#1950. This was already effectively reverted in StackExchange#1992 by not building for net6.0. Now that we are building for net6.0 again, these if-defs need to be removed.
  • Loading branch information
eerhardt committed Jun 29, 2023
1 parent 5e618dc commit f22e43e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
20 changes: 2 additions & 18 deletions src/StackExchange.Redis/ConnectionMultiplexer.ReaderWriter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;

namespace StackExchange.Redis;

Expand All @@ -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;
}

/// <summary>
/// .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.
/// </summary>
internal static SocketManager GetDefaultSocketManager()
{
#if NET6_0_OR_GREATER
return SocketManager.ThreadPool;
#else
return SocketManager.Shared;
#endif
}
}
5 changes: 0 additions & 5 deletions src/StackExchange.Redis/PhysicalBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -871,7 +867,6 @@ private void StartBacklogProcessor()
Name = "StackExchange.Redis Backlog", // help anyone looking at thread-dumps
};
thread.Start(this);
#endif
}
else
{
Expand Down
5 changes: 2 additions & 3 deletions src/StackExchange.Redis/StackExchange.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<PropertyGroup>
<Nullable>enable</Nullable>
<!-- extend the default lib targets for the main lib; mostly because of "vectors" -->
<!-- Note: we're NOT building for .NET 6 because the thread pool changes are not wins yet -->
<TargetFrameworks>net461;netstandard2.0;net472;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;net472;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<Description>High performance Redis client, incorporating both synchronous and asynchronous usage.</Description>
<AssemblyName>StackExchange.Redis</AssemblyName>
<AssemblyTitle>StackExchange.Redis</AssemblyTitle>
Expand Down Expand Up @@ -35,7 +34,7 @@
<AdditionalFiles Include="PublicAPI/PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI/PublicAPI.Unshipped.txt" />
<!-- APIs for netcoreapp3.1+ -->
<AdditionalFiles Include="PublicAPI/netcoreapp3.1/PublicAPI.Shipped.txt" Condition="'$(TargetFramework)' == 'netcoreapp3.1' or '$(TargetFramework)' == 'net5.0'" />
<AdditionalFiles Include="PublicAPI/netcoreapp3.1/PublicAPI.Shipped.txt" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/ConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit f22e43e

Please sign in to comment.