views:

642

answers:

7

Our application tends to be running very slow recently. On debugging and tracing found out that the process is showing high cpu cycles and SQL Server shows high I/O activity. Can you please guide as to how it can be optimised?

The application is now about an year old and the database file sizes are not very big or anything. The database is set to auto shrink. Its running on win2003, SQL Server 2005 and the application is a web application coded in c# i.e vs2005

+4  A: 

Run SQL Profiler on your database for a while to see if the "slowness" is due to any problem queries. Then you can analyize these queries in order to run any indexes or statistics to increase performance.

As the comment suggests though, auto shrink can result in a very fragmented database. The database will generally grow as it needs to and its usually best not to worry about how big it wants to be. As long as you perform regular transaction log backups then you're better off letting it grow. You might need to ask yourself is performance is more important than having to buy new.more disks.

You can also run some maintenance plans against the database to rebuild the indexes and statistics. This might sort things out in the short term.

Robin Day
Actually a job is scheduled to run twice a day to do the db backup to a separate disk. That was why it was set to auto shrink.
zapping
+1: Auto shrink is, 99% of the time, a bad idea. Certainly in production.
Dave Markle
If your backups are so setup and correct, then NO Autoshrink should ever have been needed. If they keep growing significantly after 24 hours, then you have something set wrong in your backups, etc.
RBarryYoung
Instead of running profiler for a period of time, I would just pull the query cache via the DMV's straight away, it will be a faster turnaround - but is 2k5 or 2k8 only, 2k would still need profiler.Before that, I think I'd also check perfmon to check for key indicators, page life expectency etc
Andrew
+4  A: 
  1. defrag your harddisk (or at least the mdf/ldf) files.
  2. put the ldf file on a separate harddisk than mdf, if possible
  3. use the the profiling tool from SQL 2005; it will tell you which requests last most; then use the "show execution plan" tool to see the steps of execution; maybe you will get a hint on what indexes should be added; for example, full table scan should be avoided for large tables.
lmsasu
The application is hosted on a dedicated server and there is lots of disk space. The database size is under 2gb. It was tending to grow about 6-7 months back. that was when the auto shrink was setup. But now the db growth is pretty much less.
zapping
+1 If autoshink has been turned on then your sql server data/log files will be fragmented to hell. Good idea to perform a defrag
Nick Kavadias
A: 

Also for frequently used queries, you can analyze them using the EXPLAIN statement. That will tell you if the appropriate indexes are being used and how many rows are being scanned.

Chris J
No EXPLAIN in SQL Server
CodeByMoonlight
oh should have been there.
zapping
The options in SSMS for displaying the Execution Plan and statistics are at least as good.
CodeByMoonlight
+1  A: 

Next to looking at performance issues with queries, I would also check whether the DB and the tables within the DB are not to much fragmented.

You can issue the DBCC showcontig statement to check this. If it shows that the tables are heavily fragmented, you should consider creating a maintenance plan that is regularly executed. In that maintenance plan, you should specify that indexes should be rebuild. By doing so, the tables will be defragged.

Frederik Gheysels
thx. will check this out.
zapping
A: 

One problem with Auto-shrink is that you have no control over when it kicks in, so it can run during live usage and make everything grind to a halt. If you really want your database to be shrunk, set a maintenance plan to do this out of hours. But I'm not sure when you'd want this option set, actually. If there's plenty of disk space, let the DB grow naturally. If there isn't, then get more. Disk space is cheap, but delays from a slow app can get expensive. Also turn off auto-close.

CodeByMoonlight
Auto close is off.
zapping
+1  A: 

Refer to this serverfault question on why having autoshrink turned on is a bad idea.

Nick Kavadias
thx. i was thinking about adding a question to get opinions on it.
zapping
A: 

Have you updated your statistics lately?

HLGEM
none has been done manually.
zapping