Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance improvement for .NET 9.0+
Browse files Browse the repository at this point in the history
MarkCiliaVincenti committed Nov 13, 2024
1 parent c9cafa1 commit d6203cc
Showing 5 changed files with 43 additions and 21 deletions.
34 changes: 17 additions & 17 deletions bus/EasyCaching.Bus.Zookeeper/DefaultZookeeperBus.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace EasyCaching.Bus.Zookeeper
using EasyCaching.Core;
using EasyCaching.Core.Bus;
using EasyCaching.Core.Serialization;
using Microsoft.Extensions.Options;
using org.apache.zookeeper;
using org.apache.zookeeper.data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace EasyCaching.Bus.Zookeeper
{
using EasyCaching.Core;
using EasyCaching.Core.Bus;
using EasyCaching.Core.Serialization;
using Microsoft.Extensions.Options;
using org.apache.zookeeper;
using org.apache.zookeeper.data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

public class DefaultZookeeperBus : EasyCachingAbstractBus
{
/// <summary>
@@ -41,7 +41,7 @@ public class DefaultZookeeperBus : EasyCachingAbstractBus
/// <summary>
/// lock
/// </summary>
private readonly object _zkEventLock = new object();
private readonly Lock _zkEventLock = LockFactory.Create();

/// <summary>
/// The serializer.
@@ -214,7 +214,7 @@ private async Task SubscribeDataChange(WatchedEvent @event)
/// <returns></returns>
private async Task ReZkConnect()
{
if (!Monitor.TryEnter(_zkEventLock, _zkBusOptions.ConnectionTimeout))
if (!_zkEventLock.TryEnter(_zkBusOptions.ConnectionTimeout))
return;
try
{
@@ -234,7 +234,7 @@ private async Task ReZkConnect()
}
finally
{
Monitor.Exit(_zkEventLock);
_zkEventLock.Exit();
}
}

10 changes: 9 additions & 1 deletion bus/EasyCaching.Bus.Zookeeper/EasyCaching.Bus.Zookeeper.csproj
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@
<Import Project="../../build/version.props" />
<Import Project="../../build/releasenotes.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Owners>ncc;Catcher Wong</Owners>
<Authors>ncc;Catcher Wong</Authors>
<VersionPrefix>$(EasyCachingZookeeperBusPackageVersion)</VersionPrefix>
@@ -40,4 +41,11 @@
<PackageReference Include="ZooKeeperNetEx" Version="3.4.12.4" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Backport.System.Threading.Lock" Version="2.0.7" />
<Using Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="System.Threading.Lock" />
<Using Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="Backport.System.Threading.Lock" />
<Using Alias="LockFactory" Include="Backport.System.Threading.LockFactory" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/EasyCaching.Core/DistributedLock/DistributedLock.cs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ namespace EasyCaching.Core.DistributedLock
public class DistributedLock : MemoryLock
{
private readonly IDistributedLockProvider _provider;
private readonly object _syncObj = new object();
private readonly Lock _syncObj = LockFactory.Create();
private readonly DistributedLockOptions _options;
private readonly ILogger _logger;

2 changes: 1 addition & 1 deletion src/EasyCaching.Core/DistributedLock/MemoryLock.cs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public class MemoryLock : IDistributedLock

public string Key { get; }

private readonly object _syncObj = new object();
private readonly Lock _syncObj = LockFactory.Create();

public MemoryLock(string key) => Key = key;

16 changes: 15 additions & 1 deletion src/EasyCaching.Core/EasyCaching.Core.csproj
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@
<Import Project="../../build/version.props" />
<Import Project="../../build/releasenotes.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Owners>ncc;Catcher Wong</Owners>
<Authors>ncc;Catcher Wong</Authors>
<VersionPrefix>$(EasyCachingCorePackageVersion)</VersionPrefix>
@@ -44,8 +45,21 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="7.0.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Backport.System.Threading.Lock" Version="2.0.7" />
<Using Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="System.Threading.Lock" />
<Using Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="Backport.System.Threading.Lock" />
<Using Alias="LockFactory" Include="Backport.System.Threading.LockFactory" />
</ItemGroup>

</Project>

0 comments on commit d6203cc

Please sign in to comment.