Skip to content

Commit 028d3b0

Browse files
committed
优化多线程下的数据解析查询
1 parent 9ce7617 commit 028d3b0

File tree

64 files changed

+2006
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2006
-257
lines changed

ShardingCore.sln

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31019.35
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{490FAE47-4476-4508-B216-505FC850447F}"
77
EndProject
@@ -49,7 +49,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShardingCore.Test3x", "test
4949
EndProject
5050
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShardingCore.Test2x", "test\ShardingCore.Test2x\ShardingCore.Test2x.csproj", "{5ED4AF17-F16D-4857-B19C-018831109991}"
5151
EndProject
52-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShardingCore.Test", "test\ShardingCore.Test\ShardingCore.Test.csproj", "{32EA64CC-0877-4B4D-BFBA-504EDB2237D6}"
52+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShardingCore.Test", "test\ShardingCore.Test\ShardingCore.Test.csproj", "{32EA64CC-0877-4B4D-BFBA-504EDB2237D6}"
53+
EndProject
54+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{B458D737-33C5-4C10-9687-0BED2E7CD346}"
55+
EndProject
56+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShardingCoreBenchmark", "benchmarks\ShardingCoreBenchmark\ShardingCoreBenchmark.csproj", "{8CE5E8AF-DDB7-4989-8AA4-1D47E4226846}"
5357
EndProject
5458
Global
5559
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -129,6 +133,10 @@ Global
129133
{32EA64CC-0877-4B4D-BFBA-504EDB2237D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
130134
{32EA64CC-0877-4B4D-BFBA-504EDB2237D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
131135
{32EA64CC-0877-4B4D-BFBA-504EDB2237D6}.Release|Any CPU.Build.0 = Release|Any CPU
136+
{8CE5E8AF-DDB7-4989-8AA4-1D47E4226846}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
137+
{8CE5E8AF-DDB7-4989-8AA4-1D47E4226846}.Debug|Any CPU.Build.0 = Debug|Any CPU
138+
{8CE5E8AF-DDB7-4989-8AA4-1D47E4226846}.Release|Any CPU.ActiveCfg = Release|Any CPU
139+
{8CE5E8AF-DDB7-4989-8AA4-1D47E4226846}.Release|Any CPU.Build.0 = Release|Any CPU
132140
EndGlobalSection
133141
GlobalSection(SolutionProperties) = preSolution
134142
HideSolutionNode = FALSE
@@ -152,6 +160,7 @@ Global
152160
{E64E09EF-2DC0-4948-A948-256EF5F95C53} = {CC2C88C0-65F2-445D-BE78-973B840FE281}
153161
{5ED4AF17-F16D-4857-B19C-018831109991} = {CC2C88C0-65F2-445D-BE78-973B840FE281}
154162
{32EA64CC-0877-4B4D-BFBA-504EDB2237D6} = {CC2C88C0-65F2-445D-BE78-973B840FE281}
163+
{8CE5E8AF-DDB7-4989-8AA4-1D47E4226846} = {B458D737-33C5-4C10-9687-0BED2E7CD346}
155164
EndGlobalSection
156165
GlobalSection(ExtensibilityGlobals) = postSolution
157166
SolutionGuid = {8C07A667-E8B4-43C7-8053-721584BAD291}

benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs

Lines changed: 384 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.EntityFrameworkCore;
7+
8+
namespace ShardingCore6x.NoShardingDbContexts
9+
{
10+
internal class DefaultDbContext:DbContext
11+
{
12+
public DefaultDbContext(DbContextOptions<DefaultDbContext> options):base(options)
13+
{
14+
15+
}
16+
protected override void OnModelCreating(ModelBuilder modelBuilder)
17+
{
18+
modelBuilder.ApplyConfiguration(new OrderMap());
19+
}
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ShardingCore6x
8+
{
9+
internal class Order
10+
{
11+
public string Id { get; set; }
12+
public long Amount { get; set; }
13+
public string Body { get; set; }
14+
public DateTime CreateTime { get; set; }
15+
public string Remark { get; set; }
16+
public string Payer { get; set; }
17+
18+
public OrderStatusEnum OrderStatus { get; set; }
19+
}
20+
21+
public enum OrderStatusEnum
22+
{
23+
NotPay=1,
24+
Succeed=1<<1,
25+
Failed=1<<2,
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
8+
9+
namespace ShardingCore6x
10+
{
11+
internal class OrderMap:IEntityTypeConfiguration<Order>
12+
{
13+
public void Configure(EntityTypeBuilder<Order> builder)
14+
{
15+
builder.HasKey(o => o.Id);
16+
builder.Property(o => o.Id).IsUnicode(false).HasMaxLength(50);
17+
builder.Property(o => o.Body).IsRequired().HasDefaultValue(string.Empty).HasMaxLength(128);
18+
builder.Property(o => o.Remark).IsRequired().HasDefaultValue(string.Empty).HasMaxLength(128);
19+
builder.Property(o => o.Payer).IsRequired().IsUnicode(false).HasMaxLength(50);
20+
builder.Property(o => o.OrderStatus).HasConversion<int>();
21+
builder.ToTable(nameof(Order));
22+
}
23+
}
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using BenchmarkDotNet.Running;
4+
using ShardingCore6x;
5+
6+
var result = BenchmarkRunner.Run<EFCoreCrud>();
7+
8+
Console.ReadLine();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<LangVersion>10.0</LangVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
13+
<PackageReference Include="EFCore.BulkExtensions" Version="6.1.1" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\..\src\ShardingCore\ShardingCore.csproj" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.EntityFrameworkCore;
7+
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
8+
using ShardingCore.Sharding;
9+
using ShardingCore.Sharding.Abstractions;
10+
11+
namespace ShardingCore6x.ShardingDbContexts
12+
{
13+
internal class DefaultShardingDbContext:AbstractShardingDbContext,IShardingTableDbContext
14+
{
15+
public DefaultShardingDbContext(DbContextOptions options) : base(options)
16+
{
17+
}
18+
19+
protected override void OnModelCreating(ModelBuilder modelBuilder)
20+
{
21+
modelBuilder.ApplyConfiguration(new OrderMap());
22+
}
23+
24+
public IRouteTail RouteTail { get; set; }
25+
}
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using ShardingCore.Core.EntityMetadatas;
7+
using ShardingCore.VirtualRoutes.Days;
8+
using ShardingCore.VirtualRoutes.Mods;
9+
10+
namespace ShardingCore6x.ShardingDbContexts
11+
{
12+
internal class OrderVirtualTableRoute:AbstractSimpleShardingModKeyStringVirtualTableRoute<Order>
13+
{
14+
public OrderVirtualTableRoute() : base(2, 5)
15+
{
16+
}
17+
public override void Configure(EntityMetadataTableBuilder<Order> builder)
18+
{
19+
builder.ShardingProperty(o => o.CreateTime);
20+
}
21+
22+
}
23+
}

samples/Sample.SqlServer/Shardings/SysUserSalaryVirtualTableRoute.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ namespace Sample.SqlServer.Shardings
1717
*/
1818
public class SysUserSalaryVirtualTableRoute:AbstractShardingOperatorVirtualTableRoute<SysUserSalary,int>
1919
{
20-
protected override int ConvertToShardingKey(object shardingKey)
21-
{
22-
return Convert.ToInt32(shardingKey);
23-
}
2420

2521
public override string ShardingKeyToTail(object shardingKey)
2622
{
27-
var time = ConvertToShardingKey(shardingKey);
23+
var time = Convert.ToInt32(shardingKey);
2824
return TimeFormatToTail(time);
2925
}
3026

0 commit comments

Comments
 (0)