简体   繁体   English

在asp.net页面上显示的巨大网格

[英]Huge Grid displayed on asp.net page

I have a major problem. 我有一个大问题。 We have a asp.net application that has this report that shows about 1000 rows as of right now and can grow up potentially up to 20,000. 我们有一个asp.net应用程序,该应用程序具有此报告,该报告目前显示大约1000行,并且可能增长到20,000。 Dont ask me why, but out client does not like paging and does not like filtering, they like to see everything on a single page. 不要问我为什么,但是客户端不喜欢分页,也不喜欢过滤,他们喜欢在单个页面上看到所有内容。 Our obvious problem is the load its putting on the server, in terms of memory (also the factor that the client browser may crash as well). 我们明显的问题是就内存而言,这是服务器的负担(也是客户端浏览器可能崩溃的因素)。

My question is: If I provide a custom desktop application only for this report, that can display thousands and thousands of rows (through web services or remotting), would it clog up the server? 我的问题是:如果仅为此报告提供一个自定义桌面应用程序,该应用程序可以显示成千上万的行(通过Web服务或远程删除),是否会阻塞服务器? On the server the worker process of the IIS basically eats up memory in case of a the asp.net application, but if I have this desktop app running seperating calling the same data base on the application server, would this solve the memory problem? 在服务器上,如果使用asp.net应用程序,则IIS的工作进程基本上会消耗内存,但是如果我运行此桌面应用程序,并在应用程序服务器上单独调用相同的数据库,是否可以解决内存问题?

Try using a lazy-loading grid such as the jqGrid: Look at the third link [virtual scrolling] on this page: 尝试使用诸如jqGrid之类的延迟加载网格:查看此页面上的第三个链接[虚拟滚动]:

http://www.trirand.net/demoaspnet.aspx http://www.trirand.net/demoaspnet.aspx

The grid uses ajax to only load the data that is visible on the page for the particular scroll position. 网格使用ajax仅为特定滚动位置加载页面上可见的数据。 Not a pger control in sight. 看不到pger控件。 Nice if you have to have this as an ASP.NET page. 很好,如果您必须将此作为ASP.NET页。

Otherwise, @jmein's suggestion to make it a download is a good one. 否则,@ jmein建议下载该文件是一个不错的选择。 Just stream the report to the Response stream, using an appropriately sized buffer. 只需使用适当大小的缓冲区将报告流式传输到响应流。

Also, read up on the use of IEnumerable<T> and the yield return statement to minimize the amount of data that you are loading into memory for streaming in the response. 另外,请阅读IEnumerable<T>yield return语句的用法,以最大程度地减少加载到内存中以便在响应中进行流式传输的数据量。

您可以根据数据创建一个excel文件,而不必担心吗?

The delivery mechanism doesn't matter - you can do this in asp.net or a desktop application without consuming a ridiculous amount of memory. 传递机制无关紧要-您可以在asp.net或桌面应用程序中执行此操作,而不会占用大量的内存。

The general principle is that you need to access the data as a stream instead of loading it into memory all at once. 一般原则是您需要将数据作为访问,而不是一次全部加载到内存中。 When you handle streamed data, you only deal with a subset of your results at any given time. 处理流数据时,在任何给定时间仅处理结果的一部分。 When you move to the next record in a stream, you're signaling that you're finished with the previous record, so the .NET runtime can reclaim the memory used manipulate it. 当您移至流中的下一条记录时,表示您已完成上一条记录,因此.NET运行时可以回收用于操纵它的内存。

In C# this means using a DataReader (normally obtained via IDbCommand.ExecuteReader ). 在C#中,这意味着使用DataReader (通常通过IDbCommand.ExecuteReader获得)。 A typical fragment that writes directly to the HttpResponse stream using a data reader might look like this (though you can databind to them as well): 使用数据读取器直接写入HttpResponse流的典型片段可能看起来像这样(尽管您也可以将数据绑定到它们):

using(IDataReader reader = dataAccessLayer.GetData()) {

    if (! reader.IsClosed) {

        // Send writes to the client immediately
        // reader.Read advances the reader to the next record in the 
        // result set and discards the current record
        while (reader.Read()) {

            // Do something with the record - this just writes the first 
            // column to the response stream.
            Response.Write(reader[0]);

            // Send the content to the client immediately, even if the content
            // is buffered. The only data in memory at any given time is the
            // row you're working on.
            Response.Flush();
        }
    }
}

If you set up a web service to return 20K records and each one is 1K, then that's a 20MB service call. 如果您设置了一个Web服务以返回20K记录,而每个记录都是1K,那么这就是20MB的服务调用。 I agree with Daniel that AJAX lazy-loading is in order here so that you fetch smaller chunks at a time. 我同意Daniel的观点,在这里AAAX延迟加载是合理的,这样您一次可以获取较小的块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM