Hi all,
I've written a few custom reports and for the most part they all work pretty well. I have one report though that is having some serious speed issues. To be fair, it's a pretty crazy report with many calculations and I wouldn't expect it to render immediately. That said, the generation time for the report take anywhere from 2 seconds to 15+ minutes with the exact same parameters and running it back to back. Literally. I've executed it in SSMS and after it completes I'll run it again exactly the same and it'll take a completely different amount of time. Funny enough, it often goes from running very quickly to running very slowly (which is the opposite of what I'd expect).
It is a complete gamble any time anyone runs the report. They either get it immediately or it times out before the report even renders for them. In the meantime, I've been running it for them directly out of SSMS and giving them the output that way. It's not ideal for anyone.
Since the speed issue also affects me in SSMS, I'm thinking that the issue must be with the stored procedure itself and not with the SSRS report face. I'm not sure how to make it more efficient though. I've tried looking at the Execution Plan but all it's telling me is to put in indexes where they already exist.
Do any of the reporting writing gurus have advice or tips for how they improve efficiencies in their own codes? I'm happy to show you what i've been working on offline if you contact me directly. I know it's not perfect but I'm trying! Still have lots to learn.
Thanks for your thoughts!
Beth
bhawryluk@winspearcentre.com
Hi Beth
Sometimes I find it easier to use the most basic debugging tool, which is to add Print statements to the stored procedure with the time it has taken to get there and a statement saying where it is in the code.
It is one way of identifying which queries are causing the delays.
Add this to start of procdeclare @debugdt datetimebefore each query addselect @debugdt=GETDATE()after each query addprint 'finish query N ' + convert(varchar(10),datediff(ms,@debugdt,getdate()))
Then in message tab you get
(1179 row(s) affected)finish query 1 910
(117 row(s) affected)finish query 2 496
(129 row(s) affected)finish query 3 1616
Will drop you an email as am happy to take a lok at the code too
Mark
If the forums had a like button, I would click it on Mark's post. I use print statements all the time to figure out where things are going wrong, both from the perspectives of too much time and unexpected data being returned.
Depending on the report and the tables you are referenceing, using NOLOCK (if you are not already doing that) could potentially shave time, though I doubt it would affect anything to that degree.
John
I usually don't like (NOLOCK) hints since people tend not to realize that it's synonymous with SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; (see Aaron Bertrand's article on the matter), but John raises a really important point -- there aren't a whole lot of reasons for a query to run slower the second time on the same connection, but a "random"-seeming pattern of execution times could indeed be the result of blocking happening as a result of other connections on the server.
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
To troubleshoot this, you would run your report until you got one of the "long execution time" runs, and then in SSMS run queries on DMVs or system procedures (or other fun things like Adam Machanic's sp_whoisactive) to find out what your query is waiting on. I'm not an expert on this, so I would recommend that you do some googling on your favorite SQL Server blogger or web resource and see if they can point you in the right direction.
Hi Beth,
You might be dealing with parameter sniffing when SQL Server creates the execution plan for this stored procedure. In a nutshell, what SQL Server tends to do is build a query plan when a stored procedure is first excuted and then it caches that plan for future use. That might work great for some parameter values, but might be a horrible plan for other values. It can result in the behavior you are describing.
One way to test to see if this is possibly impacting you is to use WITH RECOMPILE; that will tell SQL Server to build a fresh plan each time the procedure is run. After you add that, try some of your tests in SSMS after adding this to see how that impacts your results.
If it helps, you can keep WITH RECOMPILE, but there could be a performance hit due to regenerating the plan each time. If this procedure is run many times throughout the day, then you might want to target the parts of the stored procedure that are taking the longest with query hints, such as OPTIMIZE FOR.
This article describes some of those strategies: https://www.brentozar.com/archive/2013/06/the-elephant-and-the-mouse-or-parameter-sniffing-in-sql-server/
I hope this helps and good luck!
Thanks,David
> or other fun things like Adam Machanic's sp_whoisactive
Adding another vote for this. Everyone in the Tess community that is a SSMS user should install this.
You guys are all so smart and fantastic! I love it.
I'm going to take a look at your suggestions and see what I can figure out. Lots of new things to learn!
Hi Beth!
Whenever I run into head scratchers, I like to start with this nifty little tool: http://statisticsparser.com/. It was written by a guy named Richie Rump, who now works for Brent Ozar.
Basically, before you execute your stored procedure in SSMS, you set statistics IO on and set statistics time on, then after it executes you copy the message results and paste it into this web page, and ‘Shazam’ it formats all the gobblety gook that makes my eyes cross into a very readable format, which is handy for scrolling to see where my reads may be skyrocketing.
But as you say, if sometimes it runs fast and sometimes slow, it may not have anything to do with reads. So perhaps something is causing blocks? You might also try querying the plan cache. This post may help: https://dba.stackexchange.com/questions/90313/sql-server-2012-stored-procedure-runs-very-slow-sometimes
Also, check out Brent Ozar’s free tools. I can’t recommend them highly enough. One of them is specifically for the plan cache: https://www.brentozar.com/blitzcache/
Good luck!
Nancy
Nancy ShelehedaSr. Director of Application Development and Support ServicesPittsburgh Cultural Trust803 Liberty Avenue, Pittsburgh, Pa 15222412-456-1387 Sheleheda@trustarts.org | TrustArts.org
From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Beth Hawryluk Sent: Monday, September 18, 2017 12:11 AM To: Sheleheda, Nancy <Sheleheda@trustarts.org> Subject: [Tessitura Technical Forum] Troubleshooting Custom Report Issues
This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!