CPU开销过大的问题
我正在 vb.net 2005 中编写一个应用程序。该应用程序使用 ADO.NET 将电子表格读取到数据集中,并使用该表的一列来填充列表框。当选择列表框项时,将向用户显示有关所选记录的详细信息。
此信息的一部分不在数据集中。我必须将电子表格中的列与多个外部数据源进行比较,以确定相关记录的性质。这就是我的问题所在。
此比较必须在一个阶段搜索 SQL 表中的 950 万行。我已经检查过,没有办法“缩小”查询,因为我已经只搜索绝对必要的数据。
所发生的情况是应用程序从未明显执行任何操作。无论之前的情况如何,CPU 使用率都会飙升至 100%,系统性能变得几乎难以忍受。
任何人都可以提出一种方法,可以在这个大规模查询运行时改善这种情况吗?
编辑:我原本打算将数据库表中 950 万行的内容写入一个文本文件,然后从中读取该文本文件,但在 650 万行之后,我得到了 OutOfMemoryException。
I'm writing an application in vb.net 2005. The app reads a spreadsheet into a DataSet with ADO.NET and uses a column of that table to populate a ListBox. When a ListBox Item is selected, the user will be presented with detailed information on the selected record.
One part of this information isn't in the DataSet. I have to compare a column from the spreadsheet with several external data sources to determine the nature of the record in question. Here's where I have my problem.
This comparison has to search through 9.5m rows in a SQL table at one stage. I've checked and there's no way to "shrink" the query down as I'm already only searching absolutely essential data.
What happens is that the application never visibly does anything. The CPU usage shoots up to 100% regardless of what it was at beforehand and the system's performance becomes almost unbearably slow.
Can anyone suggest a way I can improve this situation while this massive query is running?
EDIT: I was originally going to write the contents of the 9.5m rows in the database table to a text file which I'd then read from, but after 6.5m rows, I got an OutOfMemoryException.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您的 CPU 可能用于填充
DataSet
,但您必须分析您的应用程序才能确认这一点。尝试使用 DataReader 来代替,并将结果以某种更紧凑的格式存储在内存中,或者如果内存不足,则将它们写入文件。使用 DataReader 方法,您永远不需要同时将整个结果集存储在内存中。I suspect your CPU might be used in populating the
DataSet
, though you would have to profile your application to confirm that. Try using aDataReader
instead and either storing the results in some more compact format in memory or, if you're running out of memory, then writing them to a file as you go. With theDataReader
approach you never need to store the entire result set in memory at the same time.