From 3270e789ae69ed83958464822fa7d35bbb4a3021 Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Fri, 17 Dec 2021 09:13:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E5=90=8C=E6=9D=A1=E4=BB=B6=E6=9F=A5=E8=AF=A2=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E8=BF=BD=E8=B8=AA=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- test/ShardingCore.Test/ShardingTest.cs | 1 + test/ShardingCore.Test/ShardingTestSync.cs | 1 + test/ShardingCore.Test2x/ShardingTest.cs | 1 + test/ShardingCore.Test2x/ShardingTestSync.cs | 1 + test/ShardingCore.Test3x/ShardingTest.cs | 1 + test/ShardingCore.Test3x/ShardingTestSync.cs | 1 + test/ShardingCore.Test5x/ShardingTest.cs | 1 + test/ShardingCore.Test5x/ShardingTestSync.cs | 1 + 9 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3cae8dac..49630c3f 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Release | EF Core | .NET | .NET (Core) ## 快速开始 5步实现按月分表,且支持自动化建表建库 ### 第一步安装依赖 - +`ShardingCore`版本表现形式为a.b.c.d,其中a表示`efcore`的版本号,b表示`ShardingCore`的主版本号,c表示`ShardingCore`次级版本号,d表示`ShardingCore`的修订版本号 ```shell # 请对应安装您需要的版本 PM> Install-Package ShardingCore @@ -38,6 +38,7 @@ PM> Install-Package ShardingCore PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer # use mysql #PM> Install-Package Pomelo.EntityFrameworkCore.MySql +# use other database driver,if efcore support ``` ### 第二步创建查询对象 @@ -238,6 +239,7 @@ AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores |----------------------------------- |--- |---------:|----------:|----------:| | NoShardingIndexFirstOrDefaultAsync | 10 | 1.512 ms | 0.0071 ms | 0.0063 ms | | ShardingIndexFirstOrDefaultAsync | 10 | 1.567 ms | 0.0127 ms | 0.0113 ms | + 针对未分片数据的查询性能,可以看出10次查询差距为0.05ms,单次查询损耗约为5微妙=0.005毫秒,损耗占比为3%, 结论:efcore 原生查询和sharding-core的查询在针对未分片对象查询上性能可达原先的97%具有极高的性能 diff --git a/test/ShardingCore.Test/ShardingTest.cs b/test/ShardingCore.Test/ShardingTest.cs index 9361d2b9..290ca882 100644 --- a/test/ShardingCore.Test/ShardingTest.cs +++ b/test/ShardingCore.Test/ShardingTest.cs @@ -537,6 +537,7 @@ namespace ShardingCore.Test var sysUserMod = await _virtualDbContext.Set().Where(o => o.Id == "1").FirstOrDefaultAsync(); Assert.NotNull(sysUserMod); Assert.True(sysUserMod.Id == "1"); + Assert.Equal(sysUserModaa, sysUserMod); var sysUserModxx = await _virtualDbContext.Set().Where(o =>x.Contains(o.Id)).FirstOrDefaultAsync(); Assert.NotNull(sysUserModxx); Assert.True(x.Contains(sysUserModxx.Id) ); diff --git a/test/ShardingCore.Test/ShardingTestSync.cs b/test/ShardingCore.Test/ShardingTestSync.cs index 777e02bc..beb46dfc 100644 --- a/test/ShardingCore.Test/ShardingTestSync.cs +++ b/test/ShardingCore.Test/ShardingTestSync.cs @@ -462,6 +462,7 @@ namespace ShardingCore.Test Assert.True(sysUserMod.Id == "1"); var sysUserModxx = _virtualDbContext.Set().Where(o => x.Contains(o.Id)).FirstOrDefault(); Assert.NotNull(sysUserModxx); + Assert.Equal(sysUserModaa, sysUserMod); Assert.True(x.Contains(sysUserModxx.Id)); Assert.NotNull(sysUserMod); var userMod = _virtualDbContext.Set().Find("1"); diff --git a/test/ShardingCore.Test2x/ShardingTest.cs b/test/ShardingCore.Test2x/ShardingTest.cs index fb465275..90638e25 100644 --- a/test/ShardingCore.Test2x/ShardingTest.cs +++ b/test/ShardingCore.Test2x/ShardingTest.cs @@ -495,6 +495,7 @@ namespace ShardingCore.Test2x var sysUserMod = await _virtualDbContext.Set().Where(o => o.Id == "1").FirstOrDefaultAsync(); Assert.NotNull(sysUserMod); Assert.True(sysUserMod.Id == "1"); + Assert.Equal(sysUserModaa, sysUserMod); var sysUserModxx = await _virtualDbContext.Set().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync(); Assert.NotNull(sysUserModxx); Assert.True(x.Contains(sysUserModxx.Id)); diff --git a/test/ShardingCore.Test2x/ShardingTestSync.cs b/test/ShardingCore.Test2x/ShardingTestSync.cs index c0e557cb..3f6064d8 100644 --- a/test/ShardingCore.Test2x/ShardingTestSync.cs +++ b/test/ShardingCore.Test2x/ShardingTestSync.cs @@ -458,6 +458,7 @@ namespace ShardingCore.Test2x var sysUserMod = _virtualDbContext.Set().Where(o => o.Id == "1").FirstOrDefault(); Assert.NotNull(sysUserMod); Assert.True(sysUserMod.Id == "1"); + Assert.Equal(sysUserModaa, sysUserMod); var sysUserModxx = _virtualDbContext.Set().Where(o => x.Contains(o.Id)).FirstOrDefault(); Assert.NotNull(sysUserModxx); Assert.True(x.Contains(sysUserModxx.Id)); diff --git a/test/ShardingCore.Test3x/ShardingTest.cs b/test/ShardingCore.Test3x/ShardingTest.cs index 11234fdb..f9d9c069 100644 --- a/test/ShardingCore.Test3x/ShardingTest.cs +++ b/test/ShardingCore.Test3x/ShardingTest.cs @@ -494,6 +494,7 @@ namespace ShardingCore.Test3x var sysUserMod = await _virtualDbContext.Set().Where(o => o.Id == "1").FirstOrDefaultAsync(); Assert.NotNull(sysUserMod); Assert.True(sysUserMod.Id == "1"); + Assert.Equal(sysUserModaa, sysUserMod); var sysUserModxx = await _virtualDbContext.Set().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync(); Assert.NotNull(sysUserModxx); Assert.True(x.Contains(sysUserModxx.Id)); diff --git a/test/ShardingCore.Test3x/ShardingTestSync.cs b/test/ShardingCore.Test3x/ShardingTestSync.cs index e7ea3ed1..7e14fcdc 100644 --- a/test/ShardingCore.Test3x/ShardingTestSync.cs +++ b/test/ShardingCore.Test3x/ShardingTestSync.cs @@ -460,6 +460,7 @@ namespace ShardingCore.Test3x var sysUserMod = _virtualDbContext.Set().Where(o => o.Id == "1").FirstOrDefault(); Assert.NotNull(sysUserMod); Assert.True(sysUserMod.Id == "1"); + Assert.Equal(sysUserModaa, sysUserMod); var sysUserModxx = _virtualDbContext.Set().Where(o => x.Contains(o.Id)).FirstOrDefault(); Assert.NotNull(sysUserModxx); Assert.True(x.Contains(sysUserModxx.Id)); diff --git a/test/ShardingCore.Test5x/ShardingTest.cs b/test/ShardingCore.Test5x/ShardingTest.cs index 71180d47..355b2b5d 100644 --- a/test/ShardingCore.Test5x/ShardingTest.cs +++ b/test/ShardingCore.Test5x/ShardingTest.cs @@ -494,6 +494,7 @@ namespace ShardingCore.Test5x var sysUserMod = await _virtualDbContext.Set().Where(o => o.Id == "1").FirstOrDefaultAsync(); Assert.NotNull(sysUserMod); Assert.True(sysUserMod.Id == "1"); + Assert.Equal(sysUserModaa, sysUserMod); var sysUserModxx = await _virtualDbContext.Set().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync(); Assert.NotNull(sysUserModxx); Assert.True(x.Contains(sysUserModxx.Id)); diff --git a/test/ShardingCore.Test5x/ShardingTestSync.cs b/test/ShardingCore.Test5x/ShardingTestSync.cs index a5637e83..36aa0b34 100644 --- a/test/ShardingCore.Test5x/ShardingTestSync.cs +++ b/test/ShardingCore.Test5x/ShardingTestSync.cs @@ -459,6 +459,7 @@ namespace ShardingCore.Test5x var sysUserMod = _virtualDbContext.Set().Where(o => o.Id == "1").FirstOrDefault(); Assert.NotNull(sysUserMod); Assert.True(sysUserMod.Id == "1"); + Assert.Equal(sysUserModaa, sysUserMod); var sysUserModxx = _virtualDbContext.Set().Where(o => x.Contains(o.Id)).FirstOrDefault(); Assert.NotNull(sysUserModxx); Assert.True(x.Contains(sysUserModxx.Id));