Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.5 work: .NET 6.0: add build defaulting to the thread pool #1939

Merged
merged 7 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Setup .NET Core 3.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
- name: Setup .NET 5.x
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
dotnet-version: |
3.1.x
5.0.x
6.0.x
- name: .NET Build
run: dotnet build Build.csproj -c Release /p:CI=true
- name: Start Redis Services (docker-compose)
Expand All @@ -50,11 +49,10 @@ jobs:
- name: Setup .NET Core 3.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
- name: Setup .NET 5.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
dotnet-version: |
3.1.x
5.0.x
6.0.x
- name: .NET Build
run: dotnet build Build.csproj -c Release /p:CI=true
- name: Start Redis Services (v3.0.503)
Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ init:

install:
- cmd: >-
choco install dotnet-sdk --version 5.0.100
choco install dotnet-sdk --version 5.0.404

choco install dotnet-sdk --version 6.0.101

cd tests\RedisConfigs\3.0.503

Expand Down
4 changes: 2 additions & 2 deletions src/StackExchange.Redis/CommandTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public string GetHelpUrl()

const string BaseUrl = "https://redis.io/commands/";

string encoded0 = Uri.EscapeUriString(((string)Arguments[0]).ToLowerInvariant());
string encoded0 = Uri.EscapeDataString(((string)Arguments[0]).ToLowerInvariant());

if (Arguments.Length > 1)
{
Expand All @@ -62,7 +62,7 @@ public string GetHelpUrl()
case "config":
case "debug":
case "pubsub":
string encoded1 = Uri.EscapeUriString(((string)Arguments[1]).ToLowerInvariant());
string encoded1 = Uri.EscapeDataString(((string)Arguments[1]).ToLowerInvariant());
return BaseUrl + encoded0 + "-" + encoded1;
}
}
Expand Down
22 changes: 20 additions & 2 deletions src/StackExchange.Redis/ConnectionMultiplexer.ReaderWriter.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
namespace StackExchange.Redis
using System;

namespace StackExchange.Redis
{
public partial class ConnectionMultiplexer
{
internal SocketManager SocketManager { get; private set; }

partial void OnCreateReaderWriter(ConfigurationOptions configuration)
{
SocketManager = configuration.SocketManager ?? SocketManager.Shared;
SocketManager = configuration.SocketManager ?? GetDefaultSocketManager();
}

partial void OnCloseReaderWriter()
{
SocketManager = null;
}
partial void OnWriterCreated();

/// <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
}
}
}
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/StackExchange.Redis.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- extend the default lib targets for the main lib; mostly because of "vectors" -->
<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
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public void DefaultThreadPoolManagerIsDetected()
EndPoints = { { IPAddress.Loopback, 6379 } },
};
using var muxer = ConnectionMultiplexer.Connect(config);
Assert.Same(SocketManager.Shared.Scheduler, muxer.SocketManager.Scheduler);
Assert.Same(ConnectionMultiplexer.GetDefaultSocketManager().Scheduler, muxer.SocketManager.Scheduler);
}

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/Migrate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Migrate : TestBase
{
public Migrate(ITestOutputHelper output) : base (output) { }

[Fact]
[FactLongRunning]
public async Task Basic()
{
var fromConfig = new ConfigurationOptions { EndPoints = { { TestConfig.Current.SecureServer, TestConfig.Current.SecurePort } }, Password = TestConfig.Current.SecurePassword, AllowAdmin = true };
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/PubSub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public async Task Issue38()
}
}

internal static Task AllowReasonableTimeToPublishAndProcess() => Task.Delay(100);
internal static Task AllowReasonableTimeToPublishAndProcess() => Task.Delay(500);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this isn't related, but is an intermittent test failure (unrelated to this PR at all) under load due to the minimal wait for publish observations vs. over large tests. Sneaking a fix in here.


[Fact]
public async Task TestPartialSubscriberGetMessage()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
<AssemblyName>StackExchange.Redis.Tests</AssemblyName>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<SignAssembly>true</SignAssembly>
Expand Down
11 changes: 3 additions & 8 deletions tests/StackExchange.Redis.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,7 @@ public static ConnectionMultiplexer CreateDefault(
}

public static string Me([CallerFilePath] string filePath = null, [CallerMemberName] string caller = null) =>
#if NET472
"net472-"
#elif NETCOREAPP3_1
"netcoreapp3.1-"
#else
"unknown-"
#endif
+ Path.GetFileNameWithoutExtension(filePath) + "-" + caller;
Environment.Version.ToString() + Path.GetFileNameWithoutExtension(filePath) + "-" + caller;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a 1:1 replacement, but the goal is to simple make it unique per version - let's go simpler and never update this with TFMs again.


protected static TimeSpan RunConcurrent(Action work, int threads, int timeout = 10000, [CallerMemberName] string caller = null)
{
Expand Down Expand Up @@ -417,7 +410,9 @@ void callback()
for (int i = 0; i < threads; i++)
{
var thd = threadArr[i];
#if !NET6_0_OR_GREATER
if (thd.IsAlive) thd.Abort();
#endif
}
throw new TimeoutException();
}
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.2",
"version": "2.5-prerelease",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this change also exists in #1912 - whichever lands first wins the v2.5-prelease versioning kick.

"versionHeightOffset": -1,
"assemblyVersion": "2.0",
"publicReleaseRefSpec": [
Expand Down