Friday, March 11, 2011

ReportViewer rendering maxes out thread CPU usage

Great solution to a problem that has been bugging me for a while... thanks
http://www.google.me/support/forum/p/Chrome/thread?tid=331a0a766d6da660&hl=en

"ReportViewer rendering maxes out thread CPU usage
[from: iainrobins] While testing our new site deployment we discovered that any page that renders a server-side SQL server report via a reportviewer ASP control, will cause the rendering thread to occupy the entire core it uses. (i.e. if you have 4 cores, it will show up as 25% CPU usage, 2 cores 50%, etc) Not exactly an ideal user experience, and I'm hoping that we won't have to tell our users not to use Chrome to view the site.


This is not a problem in any other browser we have tested (Safari, IE, Mozilla, Opera) so I doubt it's a problem with the report itself. Can anyone confirm the existence of this problem? I didn't see it in the known issues. If an example is required, we will be launching a private beta of our service in about a week and can provide a URL to a Google employee to test against.

Google Chrome version (type in about:version into the address bar): 3.0.195.27 (Official Build 28507)
Operating System: Windows XP/Vista"

Solution (from jaredhite1)

"I ended up just creating a control inheriting from ReportViewer and replacing the faulty javascript with a hack guaranteed to stop the loop. I did brief checks in IE, Chrome, Firefox, and Safari (all on Windows 7) and verified it didn't stop the normal behavior of my report, and also verified that it wasn't taking up 100% of one of my cores.


If I wanted to spend more time I'd do something more fancy, probably set a variable to make sure the location.Replace() only happens once.

using System;
using System.Web.UI;
using System.IO;

namespace MyCompany.Common
{
public class CustomReportViewer : Microsoft.Reporting.WebForms.ReportViewer
{
protected override void Render(HtmlTextWriter writer)
{
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter tmpWriter = new HtmlTextWriter(sw);
base.Render(tmpWriter);
string val = sw.ToString();
val = val.Replace(@"!= 'javascript:\'\''", @"!= 'javascript:\'\'' && false");
writer.Write(val);
}
}
}
}"

No comments:

Post a Comment