编辑:
我正在使用Fluent NHibernate,NHibernate和Oracle DB 所以我正在进行的测试如下:
[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");
});
然后是Oracle:
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");
});
然后我使用Stateless Sessions并为两个数据库进行批处理,并且可以在大约数据库中插入750000条记录到SQL DB。 100秒。
在Oracle中,相同的测试大约需要12分钟。
任何人都会看到我没有看到的任何差距错误?
答案 0 :(得分:0)
SetProperty("adonet.batch_size", "1")
因此,批处理与它无关。我们没有足够的信息来说明代码如何进行插入操作以帮助您进一步了解。
我的建议是你使用.net分析器来确定花费的时间。