C#获取从SQL查询返回的数据的大小 [英] C# Getting the size of the data returned from and SQL query

查看:565
本文介绍了C#获取从SQL查询返回的数据的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行查询时,如何获取从数据库返回的数据的字节大小?这是为了使用两种不同的技术来比较数据库服务器上的负载。我们运行的报表是从同一个数据集构建的,它会为每个报表加载整个数据集。现在我们缓存数据集并从缓存运行报告。我们对每个客户端运行报表,一些数据集比其他数据集大得多,我需要一些方法为数据库服务器负载减少提供可衡量的指标。

How can I get the size in bytes of the data returned from the database when executing a query? The reason for this is to compare load on the database server using two different techniques. We were running reports built from the same dataset which would load the entire dataset for every report. Now we are caching the dataset and running reports from the cache. We run reports per client, some datasets are significantly bigger than others, and I need some way to give a measurable metric for the database server load reduction.

通过DbConnection,DbDataReader和DbCommand为任何现有的功能,但是无法找到它。如果可能,测量给定连接或读取器的数据吞吐量将是巨大的,但是任何解决方案都是可接受的。是否可能有一个数据库服务器代理可以用来测量它?

I have tried looking through DbConnection, DbDataReader and DbCommand for any existing functionality, but was unable to find it. It would be great to measure the data throughput of a given connection or reader if possible, but any solutions are acceptable. Is there perhaps a database server proxy I can use to measure it?

数据库是Oracle 10g。

The database is Oracle 10g.

推荐答案

一种可能性是简单地使用网络嗅探器。 Wireshark 是非常好的。这将是棘手的测量通过连接(当在给定的机器上使用多个连接),但你可以使用它来测量所有的客户端机器的流量。这样做的一个好处是,它还会测量传出请求,这在您的情况(报告生成)应该很小,但仍然是总负载的一部分。

One possibility would be to simply use a network sniffer. Wireshark is amazingly good. It would be tricky to measure by connection (when using multiple connections on a given machine), but you could use it to measure all the traffic to and from a client machine. One benefit of this is that it would also measure outgoing requests, which should be small in your situation (report generation) but are still a part of the overall load.

以这种方式衡量它的另一个好处是它会发现请求大小有差异(如果有的话)。例如,如果一个方法导致在单独的请求中从服务器读取单个记录,而另一个方法导致在一个请求中读取批记录,那么您将能够看到这些差异。在这种情况下,两种方法都可能显示DbDataReader级别的总数据是相同的,但第一种方法会导致更多的网络流量。

Another benefit of measuring it this way is that it would find differences (if there are any) in the size of requests being made. For example, if one method caused individual records to be read from the server in separate requests and the other method caused a "batch" of records to be read in one request, then you would be able to see those differences. Both methods in this case might show that the total data at the DbDataReader level is the same, but the first method would result in significantly more network traffic.

Wireshark显示很多的统计数据可能对此有用。它可以提供包的总数,包的平均大小,总大小,每秒的平均字节数等。

Wireshark shows a lot of statistics that could be useful for this. It can give total number of packets, average size of packets, total size, average bytes per second, etc.

这篇关于C#获取从SQL查询返回的数据的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆