diff --git a/NewLife.Redis.sln b/NewLife.Redis.sln index b232a23..c0251ba 100644 --- a/NewLife.Redis.sln +++ b/NewLife.Redis.sln @@ -20,10 +20,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{E136AE06-927B-4D10-BB83-B607ED0B1FD4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QueueDemo", "QueueDemo\QueueDemo.csproj", "{5829188A-DC4A-4F00-AD95-5873E4057BDE}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewLife.Redis.Extensions", "NewLife.Redis.Extensions\NewLife.Redis.Extensions.csproj", "{499A9E8E-050C-40CD-90AF-FE4E499121D1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QueueDemo", "Samples\QueueDemo\QueueDemo.csproj", "{AC75EE22-B722-418F-A2A7-66020E29FE4C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "Samples\Benchmark\Benchmark.csproj", "{FAC752B8-087D-44A9-88E8-3B759A72F936}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,20 +44,25 @@ Global {08A39462-0531-45AB-ACBB-03F62AF4400F}.Debug|Any CPU.Build.0 = Debug|Any CPU {08A39462-0531-45AB-ACBB-03F62AF4400F}.Release|Any CPU.ActiveCfg = Release|Any CPU {08A39462-0531-45AB-ACBB-03F62AF4400F}.Release|Any CPU.Build.0 = Release|Any CPU - {5829188A-DC4A-4F00-AD95-5873E4057BDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5829188A-DC4A-4F00-AD95-5873E4057BDE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5829188A-DC4A-4F00-AD95-5873E4057BDE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5829188A-DC4A-4F00-AD95-5873E4057BDE}.Release|Any CPU.Build.0 = Release|Any CPU {499A9E8E-050C-40CD-90AF-FE4E499121D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {499A9E8E-050C-40CD-90AF-FE4E499121D1}.Debug|Any CPU.Build.0 = Debug|Any CPU {499A9E8E-050C-40CD-90AF-FE4E499121D1}.Release|Any CPU.ActiveCfg = Release|Any CPU {499A9E8E-050C-40CD-90AF-FE4E499121D1}.Release|Any CPU.Build.0 = Release|Any CPU + {AC75EE22-B722-418F-A2A7-66020E29FE4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC75EE22-B722-418F-A2A7-66020E29FE4C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC75EE22-B722-418F-A2A7-66020E29FE4C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC75EE22-B722-418F-A2A7-66020E29FE4C}.Release|Any CPU.Build.0 = Release|Any CPU + {FAC752B8-087D-44A9-88E8-3B759A72F936}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FAC752B8-087D-44A9-88E8-3B759A72F936}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FAC752B8-087D-44A9-88E8-3B759A72F936}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FAC752B8-087D-44A9-88E8-3B759A72F936}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {5829188A-DC4A-4F00-AD95-5873E4057BDE} = {E136AE06-927B-4D10-BB83-B607ED0B1FD4} + {AC75EE22-B722-418F-A2A7-66020E29FE4C} = {E136AE06-927B-4D10-BB83-B607ED0B1FD4} + {FAC752B8-087D-44A9-88E8-3B759A72F936} = {E136AE06-927B-4D10-BB83-B607ED0B1FD4} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {323831A1-A95B-40AB-B9AD-36A0BC10C2CB} diff --git a/NewLife.Redis/NewLife.Redis.csproj b/NewLife.Redis/NewLife.Redis.csproj index c776b91..c2ddf5b 100644 --- a/NewLife.Redis/NewLife.Redis.csproj +++ b/NewLife.Redis/NewLife.Redis.csproj @@ -56,7 +56,7 @@ - + diff --git a/Samples/Benchmark/BasicBenchmark.cs b/Samples/Benchmark/BasicBenchmark.cs new file mode 100644 index 0000000..b84be6c --- /dev/null +++ b/Samples/Benchmark/BasicBenchmark.cs @@ -0,0 +1,59 @@ +using System.Security.Cryptography; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using NewLife.Caching; +using NewLife.Security; + +namespace Benchmark; + +[SimpleJob(RunStrategy.ColdStart, iterationCount: 1)] +[MemoryDiagnoser] +public class BasicBenchmark +{ + public FullRedis Redis { get; set; } + + private String[] _keys; + + [GlobalSetup] + public void Setup() + { + var rds = new FullRedis + { + Tracer = DefaultTracer.Instance, + Log = XTrace.Log, + }; + rds.Init("server=127.0.0.1:6379;password=;db=3;timeout=5000"); + + Redis = rds; + + var ks = new String[100_000]; + for (var i = 0; i < ks.Length; i++) + { + ks[i] = Rand.NextString(16); + } + _keys = ks; + } + + [Benchmark] + public void GetTest() + { + var rds = Redis; + + for (var i = 0; i < _keys.Length; i++) + { + var value = rds.Get(_keys[i]); + } + } + + [Benchmark] + public void SetTest() + { + var rds = Redis; + var value = Rand.NextString(16); + + for (var i = 0; i < _keys.Length; i++) + { + rds.Set(_keys[i], value); + } + } +} diff --git a/Samples/Benchmark/Benchmark.csproj b/Samples/Benchmark/Benchmark.csproj new file mode 100644 index 0000000..fece7f5 --- /dev/null +++ b/Samples/Benchmark/Benchmark.csproj @@ -0,0 +1,33 @@ + + + + Exe + net8.0 + 应用后台任务 + 数据处理、定时任务、MQ生产消费、系统监控等超长独立工作的后台任务 + 新生命开发团队 + ©2002-2024 NewLife + 1.0 + $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) + $(VersionPrefix).$(VersionSuffix) + $(Version) + ..\..\Bin\Benchmark + false + enable + latest + + + + + + + + + + + + + + + + diff --git a/Samples/Benchmark/Program.cs b/Samples/Benchmark/Program.cs new file mode 100644 index 0000000..f641917 --- /dev/null +++ b/Samples/Benchmark/Program.cs @@ -0,0 +1,20 @@ +using Benchmark; +using BenchmarkDotNet.Running; +using NewLife.Caching; +using Stardust; + +//!!! 标准后台服务项目模板,新生命团队强烈推荐 + +// 启用控制台日志,拦截所有异常 +XTrace.UseConsole(); + +// 初始化对象容器,提供依赖注入能力 +var services = ObjectContainer.Current; +services.AddSingleton(XTrace.Log); + +// 配置星尘。自动读取配置文件 config/star.config 中的服务器地址 +var star = services.AddStardust(); + +var summary = BenchmarkRunner.Run(); + +Console.ReadLine(); \ No newline at end of file diff --git a/Samples/Benchmark/appsettings.json b/Samples/Benchmark/appsettings.json new file mode 100644 index 0000000..19250ac --- /dev/null +++ b/Samples/Benchmark/appsettings.json @@ -0,0 +1,22 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + //"StarServer": "http://s.newlifex.com:6600", + //"RedisCache": "server=127.0.0.1:6379;password=;db=3", + //"RedisQueue": "server=127.0.0.1:6379;password=;db=5", + "ConnectionStrings": { + "Zero": "Data Source=..\\Data\\Zero.db;Provider=SQLite" + + // 各种数据库连接字符串模版,连接名Zero对应Zero.Data/Projects/Model.xml中的ConnName + //"Zero": "Server=.;Port=3306;Database=zero;Uid=root;Pwd=root;Provider=MySql", + //"Zero": "Data Source=.;Initial Catalog=zero;user=sa;password=sa;Provider=SqlServer", + //"Zero": "Server=.;Database=zero;Uid=root;Pwd=root;Provider=PostgreSql", + //"Zero": "Data Source=Tcp://127.0.0.1/ORCL;User Id=scott;Password=tiger;Provider=Oracle" + } +} diff --git a/QueueDemo/AckQueue.cs b/Samples/QueueDemo/AckQueue.cs similarity index 100% rename from QueueDemo/AckQueue.cs rename to Samples/QueueDemo/AckQueue.cs diff --git a/QueueDemo/Area.cs b/Samples/QueueDemo/Area.cs similarity index 100% rename from QueueDemo/Area.cs rename to Samples/QueueDemo/Area.cs diff --git a/QueueDemo/DelayQueue.cs b/Samples/QueueDemo/DelayQueue.cs similarity index 100% rename from QueueDemo/DelayQueue.cs rename to Samples/QueueDemo/DelayQueue.cs diff --git a/QueueDemo/EasyQueue.cs b/Samples/QueueDemo/EasyQueue.cs similarity index 100% rename from QueueDemo/EasyQueue.cs rename to Samples/QueueDemo/EasyQueue.cs diff --git a/QueueDemo/FullQueue.cs b/Samples/QueueDemo/FullQueue.cs similarity index 100% rename from QueueDemo/FullQueue.cs rename to Samples/QueueDemo/FullQueue.cs diff --git a/QueueDemo/MemoryQueue.cs b/Samples/QueueDemo/MemoryQueue.cs similarity index 100% rename from QueueDemo/MemoryQueue.cs rename to Samples/QueueDemo/MemoryQueue.cs diff --git a/QueueDemo/MultipleConsumer.cs b/Samples/QueueDemo/MultipleConsumer.cs similarity index 100% rename from QueueDemo/MultipleConsumer.cs rename to Samples/QueueDemo/MultipleConsumer.cs diff --git a/QueueDemo/Program.cs b/Samples/QueueDemo/Program.cs similarity index 100% rename from QueueDemo/Program.cs rename to Samples/QueueDemo/Program.cs diff --git a/QueueDemo/QueueDemo.csproj b/Samples/QueueDemo/QueueDemo.csproj similarity index 78% rename from QueueDemo/QueueDemo.csproj rename to Samples/QueueDemo/QueueDemo.csproj index dafcd8d..13e5122 100644 --- a/QueueDemo/QueueDemo.csproj +++ b/Samples/QueueDemo/QueueDemo.csproj @@ -5,14 +5,14 @@ net8.0 1.0.* false - ..\Bin\QueueDemo + ..\..\Bin\QueueDemo false enable latest - + diff --git a/Test/Test.csproj b/Test/Test.csproj index 2ba2c77..4b40d34 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -16,7 +16,7 @@ - + diff --git a/XUnitTest/XUnitTest.csproj b/XUnitTest/XUnitTest.csproj index e8f24dd..6cc2a43 100644 --- a/XUnitTest/XUnitTest.csproj +++ b/XUnitTest/XUnitTest.csproj @@ -10,7 +10,7 @@ - +