原生OLE DB和ADO.NET之间的速度差异

时间:2022-01-14 21:34:18

I'm looking for suggestions as well as any benchmarks or observations people have. We are looking to rewrite our data access layer and are trying to decide between native C++ OLEDB or ADO.NET for connecting with databases. Currently we are specifically targeting Oracle which would mean we would use the Oracle OLE DB provider and the ODP.NET.

我正在寻找建议以及人们的任何基准或观察。我们正在寻找重写我们的数据访问层,并试图在本机C ++ OLEDB或ADO.NET之间决定是否与数据库连接。目前我们专门针对Oracle,这意味着我们将使用Oracle OLE DB提供程序和ODP.NET。

Requirements: 1. All applications will be in managed code so using native C++ OLEDB would require C++/CLI to work (no PInvoke way to slow). 2. Application must work with multiple databases in the future, currently just targeting Oracle specifically.

要求:1。所有应用程序都将使用托管代码,因此使用本机C ++ OLEDB将需要C ++ / CLI才能工作(没有PInvoke方式来减慢)。 2.应用程序将来必须与多个数据库一起使用,目前仅针对Oracle。

Question: 1. Would it be more performant to use ADO.NET to accomplish this or use native C++ OLE DB wrapped in a Managed C++ interface for managed code to access?

问题:1。使用ADO.NET完成此操作或使用托管C ++接口中包含的本机C ++ OLE DB以便托管代码访问是否更高效?

Any ideas, or help or places to look on the web would be greatly appreciated.

任何想法,或帮助或在网上看的地方将不胜感激。

1 个解决方案

#1


1  

I don’t think it is possible to give a single answer that is generally applicable in this situation considering the fact that you are wanting a general solution for more than just Oracle. The problem is that one vendor’s .NET provider might be faster than their OLE DB provider and vice versa for another vendor. The architecture of both of those data access technologies is significantly different.

考虑到您想要的不仅仅是Oracle的通用解决方案,我认为不可能给出一个通常适用于这种情况的单一答案。问题是一个供应商的.NET提供商可能比他们的OLE DB提供商更快,反之亦然另一个供应商。这两种数据访问技术的架构都有很大不同。

My gut feel is that the speed differences would not be that great, though. Since it sounds like you would put your own data access layer on top of OLE DB, it is hard compare directly until you wrote that. But in general, any data modification statement (e.g., UPDATE mytable set…) probably is not going to be all that different in either case. With both technologies, you specify parameter data if appropriate and then send the command to the server. The bulk of the cost is likely going to be network latency and server execution times. The biggest difference would probably come into play when reading data sets.

我的直觉是,速度差异不会那么大。因为听起来你会把你自己的数据访问层放在OLE DB之上,所以在你写这篇文章之前直接进行比较很难。但一般来说,任何数据修改语句(例如,UPDATE mytable set ......)在任何一种情况下都可能不会完全不同。使用这两种技术,您可以根据需要指定参数数据,然后将命令发送到服务器。大部分成本可能是网络延迟和服务器执行时间。在阅读数据集时,最大的差异可能会发挥作用。

Reading the data is going to be the factor that could show a difference in speed. Depending on what you are planning, you may want to read the data at a low level. For example, with OLE DB, you may call IRowset::GetNextRows. With .NET, you would maybe read through the data sets via DbDataReader::Read(). I don’t know if it is typical, but in the code I worked on, the OLE DB GetNextRows() method was much more complex than the .NET Read() implementation. I am not sure if that necessarily translates to slower execution … but it might.

读取数据将成为可能显示速度差异的因素。根据您的计划,您可能希望以较低级别读取数据。例如,使用OLE DB,您可以调用IRowset :: GetNextRows。使用.NET,您可以通过DbDataReader :: Read()读取数据集。我不知道它是否典型,但在我使用的代码中,OLE DB GetNextRows()方法比.NET Read()实现复杂得多。我不确定这是否必然转化为执行速度较慢......但它可能会。

In my opinion, the best choice would be to use ADO.NET. Since it is Microsoft's current data access technology, I suspect that vendors will update their .NET provider more often than their OLE DB provider. So if there are performance problems in implementation, the .NET provider is likely going to be fixed while their OLE DB provider may not be fixed as promptly (or at all). Also, you get a lot more flexibility with the .NET provider if you need it (e.g., entity framework). If you want that with OLE DB, you are going to need to use the .NET provider for OLE DB providers, which is another layer on top of OLE DB (assuming it would even work, which I do not know).

在我看来,最好的选择是使用ADO.NET。由于它是微软目前的数据访问技术,我怀疑供应商会比他们的OLE DB提供商更频繁地更新他们的.NET提供商。因此,如果在实现中存在性能问题,则.NET提供程序可能会被修复,而它们的OLE DB提供程序可能无法及时(或根本不)修复。此外,如果需要,您可以使用.NET提供程序获得更大的灵活性(例如,实体框架)。如果你想用OLE DB,你将需要使用.NET提供程序的OLE DB提供程序,这是OLE DB之上的另一层(假设它甚至可以工作,我不知道)。

#1


1  

I don’t think it is possible to give a single answer that is generally applicable in this situation considering the fact that you are wanting a general solution for more than just Oracle. The problem is that one vendor’s .NET provider might be faster than their OLE DB provider and vice versa for another vendor. The architecture of both of those data access technologies is significantly different.

考虑到您想要的不仅仅是Oracle的通用解决方案,我认为不可能给出一个通常适用于这种情况的单一答案。问题是一个供应商的.NET提供商可能比他们的OLE DB提供商更快,反之亦然另一个供应商。这两种数据访问技术的架构都有很大不同。

My gut feel is that the speed differences would not be that great, though. Since it sounds like you would put your own data access layer on top of OLE DB, it is hard compare directly until you wrote that. But in general, any data modification statement (e.g., UPDATE mytable set…) probably is not going to be all that different in either case. With both technologies, you specify parameter data if appropriate and then send the command to the server. The bulk of the cost is likely going to be network latency and server execution times. The biggest difference would probably come into play when reading data sets.

我的直觉是,速度差异不会那么大。因为听起来你会把你自己的数据访问层放在OLE DB之上,所以在你写这篇文章之前直接进行比较很难。但一般来说,任何数据修改语句(例如,UPDATE mytable set ......)在任何一种情况下都可能不会完全不同。使用这两种技术,您可以根据需要指定参数数据,然后将命令发送到服务器。大部分成本可能是网络延迟和服务器执行时间。在阅读数据集时,最大的差异可能会发挥作用。

Reading the data is going to be the factor that could show a difference in speed. Depending on what you are planning, you may want to read the data at a low level. For example, with OLE DB, you may call IRowset::GetNextRows. With .NET, you would maybe read through the data sets via DbDataReader::Read(). I don’t know if it is typical, but in the code I worked on, the OLE DB GetNextRows() method was much more complex than the .NET Read() implementation. I am not sure if that necessarily translates to slower execution … but it might.

读取数据将成为可能显示速度差异的因素。根据您的计划,您可能希望以较低级别读取数据。例如,使用OLE DB,您可以调用IRowset :: GetNextRows。使用.NET,您可以通过DbDataReader :: Read()读取数据集。我不知道它是否典型,但在我使用的代码中,OLE DB GetNextRows()方法比.NET Read()实现复杂得多。我不确定这是否必然转化为执行速度较慢......但它可能会。

In my opinion, the best choice would be to use ADO.NET. Since it is Microsoft's current data access technology, I suspect that vendors will update their .NET provider more often than their OLE DB provider. So if there are performance problems in implementation, the .NET provider is likely going to be fixed while their OLE DB provider may not be fixed as promptly (or at all). Also, you get a lot more flexibility with the .NET provider if you need it (e.g., entity framework). If you want that with OLE DB, you are going to need to use the .NET provider for OLE DB providers, which is another layer on top of OLE DB (assuming it would even work, which I do not know).

在我看来,最好的选择是使用ADO.NET。由于它是微软目前的数据访问技术,我怀疑供应商会比他们的OLE DB提供商更频繁地更新他们的.NET提供商。因此,如果在实现中存在性能问题,则.NET提供程序可能会被修复,而它们的OLE DB提供程序可能无法及时(或根本不)修复。此外,如果需要,您可以使用.NET提供程序获得更大的灵活性(例如,实体框架)。如果你想用OLE DB,你将需要使用.NET提供程序的OLE DB提供程序,这是OLE DB之上的另一层(假设它甚至可以工作,我不知道)。