編輯:批量插入與NHiberbnate,Oracle和功能NHibernate
我使用功能NHibernate,NHibernate的與Oracle數據庫 所以我進行測試如下:
[Test]
public void CanIInsertLargeVolumesOfDataToOracleInUnder5Mins()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var entities = GetEntities();
using (var session = UnitOfStatelessWork.GetUnderlyingSession())
{
using (var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted))
{
foreach (var entity in entities.Select(entity => new EntityObject(entity) {SomeProperty = 19675464.25M}))
{
session.Insert(entity);
}
transaction.Commit();
}
}
stopwatch.Stop();
var time = stopwatch.Elapsed;
Assert.IsTrue(time < TimeSpan.FromMinutes(5.0));
}
我連接字符串如下所示:
<connectionStrings>
<add connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=some.service.com)));User ID=user;Password=user" name="OracleConnection" providerName="Oracle.DataAccess.Client" />
</connectionStrings>
我有以下流利的配置,對於SQL Server:
var fluentConfiguration = Fluently
.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.Is(connStr)))
.Mappings(m => m.FluentMappings.AddFromAssembly(mappingAssembly));
fluentConfiguration.ExposeConfiguration(f =>
{
f.SetProperty("generate_statistics", "false");
f.SetProperty("command_timeout", "60");
f.SetListener(ListenerType.PreInsert, new AuditEventListener());
f.SetListener(ListenerType.PreUpdate, new AuditEventListener());
f.SetProperty("adonet.batch_size", "1");
f.SetProperty("hibernate.order_inserts", "true");
f.SetProperty("hibernate.order_updates", "true");
});
那麼對於甲骨文:
var fluentConfiguration = Fluently
.Configure()
.Database(OracleClientConfiguration.Oracle10.AdoNetBatchSize(1000).ConnectionString(c => c.Is(connStr)))
.Mappings(m => m.FluentMappings.AddFromAssembly(mappingAssembly));
fluentConfiguration.ExposeConfiguration(f =>
{
f.SetProperty("generate_statistics", "false");
f.SetProperty("command_timeout", "60");
f.SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
f.SetListener(ListenerType.PreInsert, new AuditEventListener());
f.SetListener(ListenerType.PreUpdate, new AuditEventListener());
f.SetProperty("hibernate.order_inserts", "true");
f.SetProperty("hibernate.order_updates", "true");
});
我然後使用無狀態會話和配料的兩個數據庫,並且可以在大約插入75萬條記錄到SQL數據庫。 100秒。
在Oracle中,同樣的測試需要大約12分鐘。
任何人都可以看到我沒有看到的任何漏洞錯誤?
因此,它看起來像NHibernate是不是在Oracle中的快速數據插入...結束使用ODP.NET和數組綁定... 750000記錄插入約。 50秒。排序! –