Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Slow query - # of processors?

Author  Topic 

im1dermike
Posting Yak Master

222 Posts

Posted - 2010-03-03 : 14:57:11
I'm trying to identify the cause of a query on a view being slow. It takes about 5 seconds to get the results. I restored the same database on my local server and I'm able to get the results immediately. The only differences I've found are:

My server:
Version: 9.00.4262.00 SP3 Developer Edition
Processors: 8
Memory: 1790 MB

Production server:
Version: 9.00.1399.06 RTM Standard Edition
Processors: 4
Memory: 16383 MB

Is it just the number of processors? Could it be a network issue (my machine and the production server are on different networks)?

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-03-03 : 15:55:46
reviewed the execution plan yet? rebuilt indexes?
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2010-03-03 : 15:59:58
I'm not sure what you mean when you say "execution plan". I just created indexes for the tables the view uses today (first time creating indexes). I created them right before I ran the query. The data in the tables isn't changing either.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-03 : 16:02:55
I'm very surprised that you have a production server running the RTM version of SQL Server 2005. There have been thousands of fixes since then. You need to make it a priority to get production upgraded to SP3 plus the latest cumulative update package. 4262 is the minimum build I'd recommend for a production server. There are higher CUs though.

We can't determine if it's a hardware issue given the information you've provided. It's not likely CPU related though. To determine if you have a hardware bottleneck, you'd need to verify it with PerfMon.

Perhaps you just have a bad execution plan in cache on the production server. Did you try DBCC FREEPROCCACHE and DBCC DROPCLEANBUFFERS on production? Note that this will have a temporary negative impact to production since all of the plans will be cleared from cache.

How often do you run update statistics in production? What's your sampling percentage on it? How often do you rebuild the indexes in production?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-03 : 16:06:58
What's your max degree of parallelism configured to (sp_configure)? For an 8 CPU box, you should probably have it set to 4. 4 is the maximum I've heard recommended by Microsoft. The default is 0 though, so unless someone changed it, that means 8 on your production server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2010-03-03 : 16:20:39
Thanks for your reply, Tara. Please forgive me. I'm just a lowly C#/ASP programmer forced to handle the tasks of database administrator/architect in my small, non-profit company. We've recently discussed about hiring a database person for a few weeks to look at our system. I'm sure this is long overdo... I will try to respond as best I can to your posts.

- I will have to read up on PerfMon to see about running it.
- I just ran DBCC FREEPROCCACHE and DBCC DROPCLEANBUFFERS on production and then re-ran my query. It was still slow.
- I don't know what update statistics are, nor sampling percentage. Up until the other day, I didn't know what indexes are and there were none in place. This morning I created some simple indexes on a handful of tables. I believe it sped up the query a little, but it's still stuck at 5 seconds which isn't really acceptable.
- I don't know what max degree of parallelism is either, but when I run sp_configure, I get the following (on both servers):

allow updates 0 1 0 0
clr enabled 0 1 0 0
cross db ownership chaining 0 1 0 0
default language 0 9999 0 0
max text repl size (B) 0 2147483647 65536 65536
nested triggers 0 1 1 1
remote access 0 1 1 1
remote admin connections 0 1 0 0
remote login timeout (s) 0 2147483647 20 20
remote proc trans 0 1 0 0
remote query timeout (s) 0 2147483647 600 600
server trigger recursion 0 1 1 1
show advanced options 0 1 0 0
user options 0 32767 0 0
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-03 : 16:23:02
Yes it will still be slow after you run the DBCC commands as the cache is now clear. Did you run it twice though? The first time you run it after the cache is cleared, it will be slower than normal. It should speed up after subsequent tries.

You'll need to enable "show advanced options" in order to see the setting.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2010-03-03 : 16:29:44
The second and subsequent query runs appear to take 4 seconds.

Ad Hoc Distributed Queries 0 1 0 0
affinity I/O mask -2147483648 2147483647 0 0
affinity mask -2147483648 2147483647 0 0
Agent XPs 0 1 0 0
allow updates 0 1 0 0
awe enabled 0 1 0 0
blocked process threshold 0 86400 0 0
c2 audit mode 0 1 0 0
clr enabled 0 1 0 0
cost threshold for parallelism 0 32767 5 5
cross db ownership chaining 0 1 0 0
cursor threshold -1 2147483647 -1 -1
Database Mail XPs 0 1 0 0
default full-text language 0 2147483647 1033 1033
default language 0 9999 0 0
default trace enabled 0 1 1 1
disallow results from triggers 0 1 0 0
fill factor (%) 0 100 0 0
ft crawl bandwidth (max) 0 32767 100 100
ft crawl bandwidth (min) 0 32767 0 0
ft notify bandwidth (max) 0 32767 100 100
ft notify bandwidth (min) 0 32767 0 0
index create memory (KB) 704 2147483647 0 0
in-doubt xact resolution 0 2 0 0
lightweight pooling 0 1 0 0
locks 5000 2147483647 0 0
max degree of parallelism 0 64 0 0
max full-text crawl range 0 256 4 4
max server memory (MB) 16 2147483647 2147483647 2147483647
max text repl size (B) 0 2147483647 65536 65536
max worker threads 128 32767 0 0
media retention 0 365 0 0
min memory per query (KB) 512 2147483647 1024 1024
min server memory (MB) 0 2147483647 0 0
nested triggers 0 1 1 1
network packet size (B) 512 32767 4096 4096
Ole Automation Procedures 0 1 0 0
open objects 0 2147483647 0 0
PH timeout (s) 1 3600 60 60
precompute rank 0 1 0 0
priority boost 0 1 0 0
query governor cost limit 0 2147483647 0 0
query wait (s) -1 2147483647 -1 -1
recovery interval (min) 0 32767 0 0
remote access 0 1 1 1
remote admin connections 0 1 0 0
remote login timeout (s) 0 2147483647 20 20
remote proc trans 0 1 0 0
remote query timeout (s) 0 2147483647 600 600
Replication XPs 0 1 0 0
scan for startup procs 0 1 0 0
server trigger recursion 0 1 1 1
set working set size 0 1 0 0
show advanced options 0 1 1 1
SMO and DMO XPs 0 1 1 1
SQL Mail XPs 0 1 0 0
transform noise words 0 1 0 0
two digit year cutoff 1753 9999 2049 2049
user connections 0 32767 0 0
user options 0 32767 0 0
Web Assistant Procedures 0 1 0 0
xp_cmdshell 0 1 0 0
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2010-03-03 : 16:31:35
How do I use Perfmon?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-03 : 17:25:39
You'll need to research it as it's a complex topic. It's not something we can answer right here in a forum without spending hours on it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2010-03-04 : 09:04:31
I will look into Permon. In the mean time, I decided to open up SQL Server Profiler and compare the query runs on each server. There was a drastic difference in the values for Reads and CPU. On my (fast) server), the values for CPU and Reads are 422 and 30,215 respectively. On the production (slow) server, the values for CPU and Reads are 5,734 and 432,699 respectively.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-03-04 : 10:01:51
rebuild all the indexes. make sure you aren'tmissing any indexes
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2010-03-04 : 10:27:38
They (only 4 indexes) are all identical and I just rebuilt them all. No change.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-03-04 : 11:00:52
it's either indexes or data. as i said earlier, what does the execution plan show you? there's a reason it's performing more 14x the reads...either because it's scanning, or because there's 14x as much data.

the cpu time is simply a function of performing all those reads and is not significant here

Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2010-03-04 : 12:00:54
I'm not really sure how to read the execution plans.

http://FastFreeFileHosting.com/file/34254/fast-sqlplan.html
http://FastFreeFileHosting.com/file/34253/slow-sqlplan.html
Go to Top of Page
   

- Advertisement -