From d6203cc247c208055709f495ff046221ea14e41c Mon Sep 17 00:00:00 2001 From: Mark Cilia Vincenti Date: Wed, 13 Nov 2024 09:38:50 +0100 Subject: [PATCH] Performance improvement for .NET 9.0+ --- .../DefaultZookeeperBus.cs | 34 +++++++++---------- .../EasyCaching.Bus.Zookeeper.csproj | 10 +++++- .../DistributedLock/DistributedLock.cs | 2 +- .../DistributedLock/MemoryLock.cs | 2 +- src/EasyCaching.Core/EasyCaching.Core.csproj | 16 ++++++++- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/bus/EasyCaching.Bus.Zookeeper/DefaultZookeeperBus.cs b/bus/EasyCaching.Bus.Zookeeper/DefaultZookeeperBus.cs index e314bf79..1ed0734b 100644 --- a/bus/EasyCaching.Bus.Zookeeper/DefaultZookeeperBus.cs +++ b/bus/EasyCaching.Bus.Zookeeper/DefaultZookeeperBus.cs @@ -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 { /// @@ -41,7 +41,7 @@ public class DefaultZookeeperBus : EasyCachingAbstractBus /// /// lock /// - private readonly object _zkEventLock = new object(); + private readonly Lock _zkEventLock = LockFactory.Create(); /// /// The serializer. @@ -214,7 +214,7 @@ private async Task SubscribeDataChange(WatchedEvent @event) /// 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(); } } diff --git a/bus/EasyCaching.Bus.Zookeeper/EasyCaching.Bus.Zookeeper.csproj b/bus/EasyCaching.Bus.Zookeeper/EasyCaching.Bus.Zookeeper.csproj index 23c4c22d..c1cb329c 100644 --- a/bus/EasyCaching.Bus.Zookeeper/EasyCaching.Bus.Zookeeper.csproj +++ b/bus/EasyCaching.Bus.Zookeeper/EasyCaching.Bus.Zookeeper.csproj @@ -3,7 +3,8 @@ - netstandard2.0;net8.0 + netstandard2.0;net8.0;net9.0 + latest ncc;Catcher Wong ncc;Catcher Wong $(EasyCachingZookeeperBusPackageVersion) @@ -40,4 +41,11 @@ + + + + + + + diff --git a/src/EasyCaching.Core/DistributedLock/DistributedLock.cs b/src/EasyCaching.Core/DistributedLock/DistributedLock.cs index 4ae267c0..9003cf33 100644 --- a/src/EasyCaching.Core/DistributedLock/DistributedLock.cs +++ b/src/EasyCaching.Core/DistributedLock/DistributedLock.cs @@ -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; diff --git a/src/EasyCaching.Core/DistributedLock/MemoryLock.cs b/src/EasyCaching.Core/DistributedLock/MemoryLock.cs index c1d01f57..5facbcfd 100644 --- a/src/EasyCaching.Core/DistributedLock/MemoryLock.cs +++ b/src/EasyCaching.Core/DistributedLock/MemoryLock.cs @@ -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; diff --git a/src/EasyCaching.Core/EasyCaching.Core.csproj b/src/EasyCaching.Core/EasyCaching.Core.csproj index 1a373291..81a35085 100644 --- a/src/EasyCaching.Core/EasyCaching.Core.csproj +++ b/src/EasyCaching.Core/EasyCaching.Core.csproj @@ -2,7 +2,8 @@ - netstandard2.0;net8.0 + netstandard2.0;net8.0;net9.0 + latest ncc;Catcher Wong ncc;Catcher Wong $(EasyCachingCorePackageVersion) @@ -44,8 +45,21 @@ + + + + + + + + + + + + +