修改readme

This commit is contained in:
xuejiaming 2022-01-07 21:48:39 +08:00
parent 752c2b028c
commit 20c758e248
3 changed files with 37 additions and 37 deletions

View File

@ -156,27 +156,27 @@ dbcontext `AbstractShardingDbContext`和`IShardingTableDbContext`如果你是普
public void ConfigureServices(IServiceCollection services)
{
services.AddShardingDbContext<MyDbContext>((conStr, builder) =>
//额外添加分片配置
services.AddShardingConfigure<MyDbContext>()
.AddEntityConfig(op =>
{
//don't modify conStr, params should use delegate input params
builder.UseSqlServer(conStr);
}).Begin(op =>
{
op.AutoTrackEntity = true;
//if use code-first should false
op.CreateShardingTableOnStart = true;
//if use code-first should false
op.EnsureCreatedWithOutShardingTable = true;
}).AddShardingTransaction((connection, builder) =>
{
//don't modify connection, params should use delegate input params
builder.UseSqlServer(connection);
}).AddDefaultDataSource("ds0",
"Data Source=localhost;Initial Catalog=EFCoreShardingTableDB;Integrated Security=True;")
.AddShardingTableRoute(op =>
{
op.UseShardingQuery((conn, builder) =>
{
builder.UseSqlServer(conn);
});
op.UseShardingTransaction((conn, builder) =>
{
builder.UseSqlServer(conn);
});
op.AddShardingTableRoute<OrderVirtualTableRoute>();
}).End();
}).AddConfig(op =>
{
op.ConfigId = "c1";
op.AddDefaultDataSource(Guid.NewGuid().ToString("n"),
"Data Source=localhost;Initial Catalog=EFCoreShardingTableDB;Integrated Security=True;");
}).EnsureConfig();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
@ -298,8 +298,7 @@ AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
| NoShardingNoIndexToListAsync | 10 | 26,068.783 ms | 103.7831 ms | 97.0788 ms | 26,094.834 ms |
| ShardingNoIndexToListAsync | 10 | 5,414.644 ms | 71.2123 ms | 59.4655 ms | 5,395.306 ms |
具体可以通过first前两次结果来计算得出结论单次查询的的损耗为0.06-0.08毫秒之间,聚合数据损耗在0.2ms-0.3左右通过数据聚合和数据路由的损耗单次在0.2ms-0.3ms,其中创建dbcontext为0.1毫秒目前没有好的优化方案,0.013毫秒左右是路由表达式解析和编译,复杂表达式可能更加耗时,剩下的0.2毫秒为数据源和表后缀的解析等操作包括实例的反射创建和数据的聚合,
sqlserver的各项数据在分表和未分表的情况下都几乎差不多可以得出在770w数据集情况下数据库还并未是数据瓶颈的关键但是mysql可以看到在分表和未分表的情况下如果涉及到没有索引的全表扫描那么性能的差距将是分表后的表数目之多测试中为5-6倍也就是分表数目
具体可以通过first前两次结果来计算得出结论单次查询的的损耗为0.06-0.08毫秒之间, sqlserver的各项数据在分表和未分表的情况下都几乎差不多可以得出在770w数据集情况下数据库还并未是数据瓶颈的关键但是mysql可以看到在分表和未分表的情况下如果涉及到没有索引的全表扫描那么性能的差距将是分表后的表数目之多测试中为5-6倍也就是分表数目
- [使用介绍](#使用介绍)

View File

@ -156,27 +156,27 @@ dbcontext `AbstractShardingDbContext`和`IShardingTableDbContext`如果你是普
public void ConfigureServices(IServiceCollection services)
{
services.AddShardingDbContext<MyDbContext>((conStr, builder) =>
//额外添加分片配置
services.AddShardingConfigure<MyDbContext>()
.AddEntityConfig(op =>
{
//don't modify conStr, params should use delegate input params
builder.UseSqlServer(conStr);
}).Begin(op =>
{
op.AutoTrackEntity = true;
//if use code-first should false
op.CreateShardingTableOnStart = true;
//if use code-first should false
op.EnsureCreatedWithOutShardingTable = true;
}).AddShardingTransaction((connection, builder) =>
{
//don't modify connection, params should use delegate input params
builder.UseSqlServer(connection);
}).AddDefaultDataSource("ds0",
"Data Source=localhost;Initial Catalog=EFCoreShardingTableDB;Integrated Security=True;")
.AddShardingTableRoute(op =>
{
op.UseShardingQuery((conn, builder) =>
{
builder.UseSqlServer(conn);
});
op.UseShardingTransaction((conn, builder) =>
{
builder.UseSqlServer(conn);
});
op.AddShardingTableRoute<OrderVirtualTableRoute>();
}).End();
}).AddConfig(op =>
{
op.ConfigId = "c1";
op.AddDefaultDataSource(Guid.NewGuid().ToString("n"),
"Data Source=localhost;Initial Catalog=EFCoreShardingTableDB;Integrated Security=True;");
}).EnsureConfig();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

View File

@ -43,6 +43,7 @@ namespace ShardingCore.Test
op.EnsureCreatedWithOutShardingTable = true;
//当无法获取路由时会返回默认值而不是报错
op.ThrowIfQueryRouteNotMatch = false;
op.AddShardingDataSourceRoute<OrderAreaShardingVirtualDataSourceRoute>();
op.AddShardingTableRoute<SysUserModVirtualTableRoute>();
op.AddShardingTableRoute<SysUserSalaryVirtualTableRoute>();
@ -61,7 +62,7 @@ namespace ShardingCore.Test
.AddConfig(op =>
{
op.ConfigId="c1";
op.Priority = 1;
op.UseShardingQuery((conStr, builder) =>
{
builder.UseSqlServer(conStr).UseLoggerFactory(efLogger);