Timeouts

  • Hi All,

    There is a developer who claims he is seeing timeouts in the error logs that are being caused by the database. The procedures in question are optimized and run in milliseconds. The catch is that when the procs are called they are called several thousand times in a very short period of time (seconds). When this is happening I am running sp_who2 active and do not see any blocking.

    Can somebody please advise me how i can track these procedures to see whether or not they are causing blocking which is in turn causing these time outs? I would like to generate some metrics to go back to them with so we can work to troubleshoot these timeouts.

    Thanks so much in advance....

    Paul

  • Hi Paul,

    The server doesn't timeout when running a query (linked servers aside). It's the client that tells the server to cancel a query based on its command timeout value.

    You should be able to see when the client sends a request to cancel by capturing Attention Events in a SQL Profiler trace .

  • Thank you for your response. Our app times out after 30 seconds and inserts an error in the log file. The sp in question run in SSMS in under 1 second. How would I determine why it is taking more than 30 when called via the application. Again its being called a ton in a very short period of time, but how would i go about putting metrics to that so we can go back and analyze?

  • Isn't it strange how problems like this are always the fault of the database and not the developer? :crazy:

    Anyway, I'd be inclined to set up a trace on the server so you can see exactly what SQL commands are being executed and how long they're taking. It'll add a bit of extra load, obviously, but if anything that should make the problem happen sooner and thus be easier to trace!

  • paul.corujo (6/2/2010)


    The sp in question run in SSMS in under 1 second. How would I determine why it is taking more than 30 when called via the application.

    if its running fine then thats not DBA's call it should be kept in Developers plate. but one concern is there that is "tons of call"

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • If you're looking to track how long each query is taking you can have profiler log to a table or a file and then do averages on the duration. If you're logging to file you can use fn_trace_gettable to access the information in a query window.

    Don't forget to take the network into account when considering the cause of problems like this. Do either the client or the server have any errors in Event Viewer when this is happening?

  • paul.corujo (5/26/2010)


    ... When this is happening I am running sp_who2 active and do not see any blocking. Can somebody please advise me how i can track these procedures to see whether or not they are causing blocking which is in turn causing these time outs? ...

    When a stored procedure that normally runs in under a second sporatically takes 30 seconds or longer to execute, then it's typically the result of some type of blocking.

    You can turn on trace flag 1222 or use SQL Profiler to log deadlocks, a special blocking scenario where one process is aborted to allow the other to finish. The following article describes steps for tracing deadlocks and resolving excessive blocking, if that turns out to be the issue.

    http://blogs.msdn.com/b/bartd/archive/2006/09/09/deadlock-troubleshooting_2c00_-part-1.aspx

    Even highly optimized T-SQL and indexes will take you so far. You may even want to redesign your application workflow so that this stored procedure, which you said gets occasionally gets executed thousands of times a second, is instead executed in small sequential batches.

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • That is perfect, thank you all for your help.

  • I am going to try this in dev first but should I expect a big performance issue if I enable flag 1222?

  • No.

    Are you seeing deadlocks? Are you having queries failing with the error "Transaction X was deadlocked and was chosen as the deadlock victim"? Deadlocks and blocking are two different (though related) things. If you're just having blocking, the deadlock trace may not show anything up at all.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • The error log just shows time out but that is an error log written to by the app. The SQL Logs do not show any deadlock errors, but without logging on would it? How would I go about tracking down and resolving excessive blocking? We do monitor using Orion and it pages that there are blocks. We think the blocking is causing the app to time out. It is set to timeout in 30 seconds.

  • I'd suggest start with Profiler. Find long-running queries and see if you can tune them. These may help.

    http://www.simple-talk.com/sql/performance/finding-the-causes-of-poor-performance-in-sql-server,-part-1/

    http://www.simple-talk.com/sql/performance/finding-the-causes-of-poor-performance-in-sql-server,-part-2/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • In addition to duration, I would look at start and stop times of each call. The duration is just the amount of time within SQL Server. If there is something slowing down the calls on the client or in the network connection, there will be time gap between the end of one call and the beginning of the next.

    David Lathrop
    DBA
    WA Dept of Health

  • You mentioned earlier that your application may on occasion be executing this procedure thousands of times per second. There are several different things that can cause blocking. One is blocking due to recompiling.

    Google: "sql server" recompile locks blocking

    Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server 2005

    http://technet.microsoft.com/en-us/library/cc966425.aspx

    HOW TO: Use KEEPFIXED PLAN to Disable Stored Procedure Recompilations

    http://support.microsoft.com/kb/276220

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply