加载时提高Page的性能

时间:2022-08-24 17:41:22

I have a .aspx screen that displays some data in an asp:GridView component. There can be up to approx 30k records returned when page loads. it is taking appr 30 sec to retrieve the 13000 records from the database.IS this slow or fast? am using stored procedure to retrieve the records from the database n am querying the database only once and storing it. then there is a foreach loop which is taking more than 2 mins to execute? so it taking aapr 4 min to load the page.

我有一个.aspx屏幕,在asp:GridView组件中显示一些数据。页面加载时最多可返回约30k条记录。它需要30秒才能从数据库中检索13000条记录。这种速度是慢还是快?我使用存储过程从数据库中检索记录n我只查询数据库一次并存储它。然后有一个foreach循环,执行时间超过2分钟?所以它花了4分钟来加载页面。

I am just a beginner to asp.net .can you please help me out to improve the delay in when page loads?

我只是asp.net的初学者。你可以帮助我改善页面加载时的延迟吗?

here is the looping structure ..can we optimize it in any way?

这是循环结构..我们可以以任何方式优化它吗?

List auditList = retrievedatafromdatabase();//This method returns records from database

List auditList = retrieveatafromdatabase(); //此方法从数据库返回记录

               foreach (Entity obj in auditList)
                {

                    obj.CultSpecificRevisedData = "NULL";
                    obj.CultSpecificPublishedData = "NULL";

                    if (obj.RevisedData != null && obj.RevisedData != "NULL")
                        obj.CultSpecificRevisedData = ConvertToProfileSpecificFormat(Convert.ToDecimal(obj.RevisedData), DecimalSeparator);
                    if (obj.PublishedData != null && obj.PublishedData != "NULL")
                        obj.CultSpecificPublishedData = ConvertToProfileSpecificFormat(Convert.ToDecimal(obj.PublishedData), DecimalSeparator);

                    var yearPart = obj.CalendarYear;
                    var monthPart = string.Empty;
                    var frequencyName = GetEnglishFrequencyBame(frequencyTypeMasId);
                    if (frequencyName == FrequencyType.Monthly)
                    {
                        monthPart = new DateTime(obj.CalendarYear, GetMonthNumber(obj.Month), 1).ToString("MMM");
                        obj.CultSpecificPeriod = monthPart + "-" + yearPart.ToString();
                    }
                    if (frequencyName == FrequencyType.Quarterly)
                    {
                      UserMessage = obj.QuarterName;
                        obj.CultSpecificPeriod = UserMessage + "-" + yearPart.ToString();
                    }
                    else if (frequencyName == FrequencyType.BiAnnually)
                    {
                        UserMessage = obj.SemesterName;
                        obj.CultSpecificPeriod = UserMessage + "-" + yearPart.ToString();
                    }
                    else
                    {
                        obj.CultSpecificPeriod = yearPart.ToString();
                    }


                }

2 个解决方案

#1


2  

Paging is your first option.

分页是您的第一选择。

But you should consinder the following: Do you really need 30K records ? users don't usually go through the first 10\20 records, try returning only the first 100\1000 and giving good search and filter capabilities that will limit the result set scientifically.

但你应该补充以下内容:你真的需要30K记录吗?用户通常不会通过前10 \ 20记录,尝试仅返回前100 \ 1000并提供良好的搜索和过滤功能,这将限制科学结果集。

I had the same problem and I understood that the users dose not need that many results they need a good way of finding what they want out of these results.

我有同样的问题,我明白用户不需要那么多的结果,他们需要一个很好的方法来找到他们想要的结果。

of course that could be incorporated together with paging.

当然,这可以与分页结合在一起。

If paging dosen't suit your solution (for some reason) The you do not agree with what was said, post some code and we'll try to help with performance optimization. keep in mind that it's a very hard task sometimes.

如果分页不适合您的解决方案(由于某种原因)您不同意所说的内容,发布一些代码,我们将尝试帮助进行性能优化。请记住,有时这是一项非常艰巨的任务。

#2


0  

I'll echo comments about not really needing 30K records. Research shows that humans can't really visually process anything more than about 2000 list items, and if you're showing more than this you're effectively lying to your users by encouraging them to get a false or incomplete sense of the data.

我会回应关于不需要30K记录的评论。研究表明,人类无法在视觉上处理超过大约2000个列表项目的任何内容,如果您展示的不仅仅是这些,那么通过鼓励他们获得错误或不完整的数据感知,您实际上会欺骗用户。

But if you persist in doing this, what you want to do is iterate through the records set by hand, use Response.Write() to manually compose the html for each row and send it to the browser, and then use a counter to call Response.Flush() every now and then. Bonus points if your data layer supports streaming the data from your database as well (ie: via a datareader) rather than loading the entire result set into RAM.

但是如果你坚持这样做,你要做的就是遍历手工设置的记录,使用Response.Write()手动编写每行的html并将其发送到浏览器,然后使用计数器调用Response.Flush()时不时。如果您的数据层也支持从数据库中流式传输数据(即:通过数据加载器),而不是将整个结果集加载到RAM中,则可获得奖励积分。

#1


2  

Paging is your first option.

分页是您的第一选择。

But you should consinder the following: Do you really need 30K records ? users don't usually go through the first 10\20 records, try returning only the first 100\1000 and giving good search and filter capabilities that will limit the result set scientifically.

但你应该补充以下内容:你真的需要30K记录吗?用户通常不会通过前10 \ 20记录,尝试仅返回前100 \ 1000并提供良好的搜索和过滤功能,这将限制科学结果集。

I had the same problem and I understood that the users dose not need that many results they need a good way of finding what they want out of these results.

我有同样的问题,我明白用户不需要那么多的结果,他们需要一个很好的方法来找到他们想要的结果。

of course that could be incorporated together with paging.

当然,这可以与分页结合在一起。

If paging dosen't suit your solution (for some reason) The you do not agree with what was said, post some code and we'll try to help with performance optimization. keep in mind that it's a very hard task sometimes.

如果分页不适合您的解决方案(由于某种原因)您不同意所说的内容,发布一些代码,我们将尝试帮助进行性能优化。请记住,有时这是一项非常艰巨的任务。

#2


0  

I'll echo comments about not really needing 30K records. Research shows that humans can't really visually process anything more than about 2000 list items, and if you're showing more than this you're effectively lying to your users by encouraging them to get a false or incomplete sense of the data.

我会回应关于不需要30K记录的评论。研究表明,人类无法在视觉上处理超过大约2000个列表项目的任何内容,如果您展示的不仅仅是这些,那么通过鼓励他们获得错误或不完整的数据感知,您实际上会欺骗用户。

But if you persist in doing this, what you want to do is iterate through the records set by hand, use Response.Write() to manually compose the html for each row and send it to the browser, and then use a counter to call Response.Flush() every now and then. Bonus points if your data layer supports streaming the data from your database as well (ie: via a datareader) rather than loading the entire result set into RAM.

但是如果你坚持这样做,你要做的就是遍历手工设置的记录,使用Response.Write()手动编写每行的html并将其发送到浏览器,然后使用计数器调用Response.Flush()时不时。如果您的数据层也支持从数据库中流式传输数据(即:通过数据加载器),而不是将整个结果集加载到RAM中,则可获得奖励积分。