NHibernate 似乎没有批量插入 PostgreSQL
我正在使用 NHibernate 连接 PostgreSQL 数据库。
背景
我做了一些简单的测试...似乎需要 2 秒才能保存 300 条记录。 我有一个具有相同功能的 Perl 程序,但直接发出 SQL,只花费 70% 的时间。 我不确定这是否是预期的。我认为 C#/NHibernate 会更快或者至少不相上下。
问题
我的观察之一是(在 show_sql
打开的情况下),NHibernate 发出数百次 INSERT,而不是执行处理多行的批量 INSERT。请注意,我自己分配主键,而不是使用“本机”生成器。
这是预期的吗?无论如何,我可以让它发出批量 INSERT 语句吗?在我看来,这可能是我可以加快性能的领域之一。
I am interfacing with a PostgreSQL database with NHibernate.
Background
I made some simple tests...it seems it's taking 2 seconds to persist 300 records.
I have a Perl program with identical functionality, but issue direct SQL instead, takes only 70% of the time.
I am not sure if this is expected. I thought C#/NHibernate would be faster or at least on par.
Questions
One of my observation is that (with show_sql
turned on), the NHibernate is issuing INSERTs a few hundreds times, instead of doing bulk INSERT that take cares of multiple rows. And note I am assigning the primary key myself, not using the "native" generator.
Is that expected? Is there anyway I could make it issue bulk INSERT statement instead? It seems to me that this could be one of the area I could speed up the performance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 stachu 正确发现的那样:NHibernate 没有用于 PostgreSQL(Npgsql) 的 *BatchingBatcher(Factory)
正如 stachu 所问:是否有人设法强制 Nhibarnate 对 PostgreSQL 进行批量插入
? ..),(...),...)
As stachu found out correctly: NHibernate does not have *BatchingBatcher(Factory) for PostgreSQL(Npgsql)
As stachu askes: Did anybody managed to force Nhibarnate to do batch inserts to PostgreSQL
I wrote a Batcher that doesn't use any Npgsql batching stuff, but does manipulate the SQL String "oldschool style" (INSERT INTO [..] VALUES (...),(...), ...)
我还发现 NHibernate 没有对 PostgreSQL 进行批量插入。
我发现了两个可能的原因:
1)Npgsql驱动程序不支持批量插入/更新(参见论坛)
2) NHibernate 没有用于 PostgreSQL(Npgsql) 的 *BatchingBatcher(Factory)。我尝试将 Devart dotConnect 驱动程序与 NHibernate 一起使用(我为 NHibernate 编写了自定义驱动程序),但它仍然不起作用。
我想这个驱动程序还应该实现 IEmbeddedBatcherFactoryProvider 接口,但这对我来说似乎并不简单(对 Oracle 使用一个接口不起作用;))
是否有人设法强制 Nhibarnate 对 PostgreSQL 进行批量插入或者可以证实我的结论?
I also found that NHibernate is not doing batch inserts into PostgreSQL.
I identified two possible reasons:
1) Npgsql driver does not support batch inserts/updates (see forum)
2) NHibernate does not have *BatchingBatcher(Factory) for PostgreSQL(Npgsql). I tried using Devart dotConnect driver with NHibernate (I wrote custom driver for NHibernate) but it still did not worked.
I suppose this driver should also implement IEmbeddedBatcherFactoryProvider interface, but it seems not trivial for me (using one for Oracle did not worked ;) )
Did anybody managed to force Nhibarnate to do batch inserts to PostgreSQL or can confirm my conclusion?