Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Here is the issue overview: Why does my stored procedure run faster when executed localy vs remotely?

Dont jump to any conclusion just yet, let me explain what I mean...

Here is the setup:
A Windows 2008R2 (correction: 2003) application server executes a stored procedure that performs some action, (what its doing is really important at this point in time). This stored procedure is executed on the SQL server over a TCP/IP connection to the database server. The DB server is physicaly located right next to the application server, and they are connected to eachother via 1GB NICs to a 1GB Switch. The DB server is running SQL 2005 SP2 Enterprise Edition, and has 16GB of memory and several vLUNS striped across 48 15k drives in an HP-EVA FC connected SAN. From all indicators thus far, there are no I/O, Mem, or CPU constreints or limits being hit. Trace Falg 1118 is on and TempDB is split across 8 file on their own vLUN. Data, and TLogs also have their own vLUNS too.

So, here is what I am seeing:
Using SQLCMD on the database server, with SQLProfiler running from the same DB server, I can execute the stored procedure and I see that the execution starts immediatly, and compleats with a durration of about 2,100ms with an IO of about 1200.

Using SQLCMD on the application server, with SQLProfiler running from the DB server, I can execute the same exact stored procedure, with the SAME exact parameters, and I see that the execution starts immediatly, and compleats with a durration of about 110,000ms with an IO of about 1200.

The query results in 1 row, with 4 columns [INT, INT, VARCHAR(50), VARCHAR(100)]

ASIDE:(I know the query is a train wreck, this is a regulated system and I cannot change it on a live prodution server, so please dont make any sugestions about doing so. The next version has been rewritten to be better.)

From everything we can see, there is no reason that we should be seeing differances like this, but what is heppening is the .NET application that calls this query from the application server is timing out waiting for the responce.

We have checked locking and blocking, WAIT states, Query plans, IO contention, CPU contention, MEM contention, NETWORK saturation/utilization, performed indexes rebuilds on all indexes, updates all stats, and a hand full of other items, but haven't come up with anything that points to why this is happening.

Please ask more questions if you have any, make recomendations as you come up with them, and depending on the impact (remember this is a production environment) we will try them and respond back.

-Thanks! -Chris

share|improve this question

closed as too localized by Mark Storey-Smith, StanleyJohns, Max Vernon, dezso, RolandoMySQLDBA Jun 24 '13 at 14:54

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Your description would seem to clearly indicate a nic/network problem. Make sure the nics and switches in between are set to the same setting (preferably Auto). If the speeds do not match, the connection to the nic defaults to single duplex rather than half duplex which means it does I or O at any given time, not both. –  Robert L Davis Mar 13 '13 at 20:05
1  
Check the connections between the two. How long does a ping/traceroute from the app server to the db server take? And reverse. Also check IPSec which can add a lot of overload to the processing of data. –  Robert L Davis Mar 13 '13 at 20:08
1  
Check to see if the nic is configured correctly for tcp chimney and offloading as well. –  Robert L Davis Mar 13 '13 at 20:09
    
Adding to what Robert has mentioned - Is the NIC card configured in FULL DUPLEX mode ? –  Kin Mar 13 '13 at 20:15
1  
If the list of "checked" is as comprehensive as you suggest, I'd be inclined to crack out Wireshark. Alternatively, show us the data you've gathered. Here is a great example question that demonstrates the benefit of sharing the detail of your investigations. –  Mark Storey-Smith Mar 13 '13 at 23:21
show 5 more comments

3 Answers 3

This is not a networking issue (though that is tempting).

This is almost certainly "noise." What I mean here is that you need to run this operation perhaps 100 times on the db server itself and from the app server, preferably over a span of 2 hours or so (or more).

What I strongly expect you will find is that at certain times it runs fast on either/both systems, and at certain times it is slow no matter where it is initiated.

E.g. the SQL workload is what you are actually measuring, not the network.

share|improve this answer
    
We will give this a run for the money, but something else has raised an idea too, without giving too much information away, this procedure runs fairly often, and it seems that with certian sets of parameters (namely specific account numbers) , its more likely to perform slowly than not, hoever there is no rhym or reason for why the accountnumber matters. In some cases the account is old with lots of entries, and in other its a brand new account. –  RenoDBA Mar 13 '13 at 22:03
    
@RenoDBA If what you describe above is actually the case, then my answer above is correct: It is not where the command is run from... it is when/with what params... e.g. what you are measuring is SQL load.... –  samsmith Mar 14 '13 at 0:25
add comment

If you execute them both from SSMS, using the 'Include Client Statistics' option in the Query menu you should be able to compare the bottom row "Wait Time on server replies" to validate. You may also get more insight into the amount of network chatter.

share|improve this answer
    
only have SSMS on the DB server, using SQLCMD for testing. Have run it with stats io on, but that got really hard to read. What is the SQL command to get the Wait Time on Server Replies from SQLCMD? –  RenoDBA Mar 13 '13 at 21:36
    
I believe if you add -p to SQLCMD you get some statistics, not sure if they line up with what is in SSMS. –  Richard Schweiger Mar 13 '13 at 21:45
add comment

Sounds like a connection issue or plan issue:

http://www.sommarskog.se/query-plan-mysteries.html

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.