benchmark

This commit is contained in:
xuejiaming 2021-12-06 14:46:53 +08:00
parent a68c3b8ec5
commit f18872cc60
1 changed files with 59 additions and 60 deletions

View File

@ -64,76 +64,75 @@ namespace ShardingCore6x
.UseSqlServer(connection) .UseSqlServer(connection)
) )
//.AddDefaultDataSource("ds0", "server=127.0.0.1;port=3306;database=db2;userid=root;password=L6yBtV6qNENrwBy7;") //.AddDefaultDataSource("ds0", "server=127.0.0.1;port=3306;database=db2;userid=root;password=L6yBtV6qNENrwBy7;")
//.AddDefaultDataSource("ds0", "Data Source=localhost;Initial Catalog=db2;Integrated Security=True;") .AddDefaultDataSource("ds0", "Data Source=localhost;Initial Catalog=db2;Integrated Security=True;")
.AddDefaultDataSource("ds0", "Data Source=localhost;Initial Catalog=db1;Integrated Security=True;")
.AddShardingTableRoute(op => .AddShardingTableRoute(op =>
{ {
//op.AddShardingTableRoute<OrderVirtualTableRoute>(); op.AddShardingTableRoute<OrderVirtualTableRoute>();
}).End(); }).End();
var buildServiceProvider = services.BuildServiceProvider(); var buildServiceProvider = services.BuildServiceProvider();
buildServiceProvider.GetRequiredService<IShardingBootstrapper>().Start(); buildServiceProvider.GetRequiredService<IShardingBootstrapper>().Start();
//ICollection<Order> orders = new LinkedList<Order>(); ICollection<Order> orders = new LinkedList<Order>();
//using (var scope = buildServiceProvider.CreateScope()) using (var scope = buildServiceProvider.CreateScope())
//{ {
// var defaultShardingDbContext = scope.ServiceProvider.GetService<DefaultDbContext>(); var defaultShardingDbContext = scope.ServiceProvider.GetService<DefaultDbContext>();
// defaultShardingDbContext.Database.EnsureCreated(); defaultShardingDbContext.Database.EnsureCreated();
// if (!defaultShardingDbContext.Set<Order>().Any()) if (!defaultShardingDbContext.Set<Order>().Any())
// { {
// var begin = DateTime.Now.Date.AddDays(-8); var begin = DateTime.Now.Date.AddDays(-8);
// var now = DateTime.Now; var now = DateTime.Now;
// var current = begin; var current = begin;
// int i = 0; int i = 0;
// var x = new OrderStatusEnum[] { OrderStatusEnum.Failed, OrderStatusEnum.NotPay, OrderStatusEnum.Succeed }; var x = new OrderStatusEnum[] { OrderStatusEnum.Failed, OrderStatusEnum.NotPay, OrderStatusEnum.Succeed };
// while (current < now) while (current < now)
// { {
// orders.Add(new Order() orders.Add(new Order()
// { {
// Id = i.ToString(), Id = i.ToString(),
// Amount = i, Amount = i,
// Body = $"今天购买了的东西呀:{i}", Body = $"今天购买了的东西呀:{i}",
// CreateTime = current, CreateTime = current,
// Remark = $"这是我的备注哦备注哦备注哦:{i}", Remark = $"这是我的备注哦备注哦备注哦:{i}",
// Payer = Guid.NewGuid().ToString("n"), Payer = Guid.NewGuid().ToString("n"),
// OrderStatus = x[i % 3] OrderStatus = x[i % 3]
// }); });
// i++; i++;
// current = current.AddMilliseconds(100); current = current.AddMilliseconds(100);
// } }
// var sp = Stopwatch.StartNew(); var sp = Stopwatch.StartNew();
// defaultShardingDbContext.BulkInsert<Order>(orders.ToList()); defaultShardingDbContext.BulkInsert<Order>(orders.ToList());
// sp.Stop(); sp.Stop();
// Console.WriteLine($"批量插入订单数据:{orders.Count},用时:{sp.ElapsedMilliseconds}"); Console.WriteLine($"批量插入订单数据:{orders.Count},用时:{sp.ElapsedMilliseconds}");
// } }
//} }
//using (var scope = buildServiceProvider.CreateScope()) using (var scope = buildServiceProvider.CreateScope())
//{ {
// var defaultShardingDbContext = scope.ServiceProvider.GetService<DefaultShardingDbContext>(); var defaultShardingDbContext = scope.ServiceProvider.GetService<DefaultShardingDbContext>();
// if (!defaultShardingDbContext.Set<Order>().Any()) if (!defaultShardingDbContext.Set<Order>().Any())
// { {
// var sp = Stopwatch.StartNew(); var sp = Stopwatch.StartNew();
// var bulkShardingEnumerable = defaultShardingDbContext.BulkShardingTableEnumerable(orders.ToList()); var bulkShardingEnumerable = defaultShardingDbContext.BulkShardingTableEnumerable(orders.ToList());
// foreach (var keyValuePair in bulkShardingEnumerable) foreach (var keyValuePair in bulkShardingEnumerable)
// { {
// keyValuePair.Key.BulkInsert(keyValuePair.Value.ToList()); keyValuePair.Key.BulkInsert(keyValuePair.Value.ToList());
// } }
// sp.Stop(); sp.Stop();
// Console.WriteLine($"批量插入订单数据:{orders.Count},用时:{sp.ElapsedMilliseconds}"); Console.WriteLine($"批量插入订单数据:{orders.Count},用时:{sp.ElapsedMilliseconds}");
// } }
//} }
_defaultDbContext = ShardingContainer.GetService<DefaultDbContext>(); _defaultDbContext = ShardingContainer.GetService<DefaultDbContext>();
_defaultShardingDbContext = ShardingContainer.GetService<DefaultShardingDbContext>(); _defaultShardingDbContext = ShardingContainer.GetService<DefaultShardingDbContext>();
//_virtualTableManager = ShardingContainer.GetService<IVirtualTableManager<DefaultShardingDbContext>>(); _virtualTableManager = ShardingContainer.GetService<IVirtualTableManager<DefaultShardingDbContext>>();
//_virtualTable = _virtualTableManager.GetVirtualTable<Order>(); _virtualTable = _virtualTableManager.GetVirtualTable<Order>();
//_routeTailFactory = ShardingContainer.GetService<IRouteTailFactory>(); _routeTailFactory = ShardingContainer.GetService<IRouteTailFactory>();
//_streamMergeContextFactory = _streamMergeContextFactory =
// ShardingContainer.GetService<IStreamMergeContextFactory<DefaultShardingDbContext>>(); ShardingContainer.GetService<IStreamMergeContextFactory<DefaultShardingDbContext>>();
//_actualConnectionStringManager = new ActualConnectionStringManager<DefaultShardingDbContext>(); _actualConnectionStringManager = new ActualConnectionStringManager<DefaultShardingDbContext>();
//_virtualDataSource = ShardingContainer.GetService<IVirtualDataSource<DefaultShardingDbContext>>(); _virtualDataSource = ShardingContainer.GetService<IVirtualDataSource<DefaultShardingDbContext>>();
// _dataSourceRouteRuleEngineFactory = ShardingContainer.GetService<IDataSourceRouteRuleEngineFactory<DefaultShardingDbContext>>(); _dataSourceRouteRuleEngineFactory = ShardingContainer.GetService<IDataSourceRouteRuleEngineFactory<DefaultShardingDbContext>>();
// _tableRouteRuleEngineFactory = ShardingContainer.GetService<ITableRouteRuleEngineFactory<DefaultShardingDbContext>>(); _tableRouteRuleEngineFactory = ShardingContainer.GetService<ITableRouteRuleEngineFactory<DefaultShardingDbContext>>();
} }