Question : Set Maximum Processor Usage

We are using MS SQL 2005 at work.  The MS SQL 2005 is installed on a really high end new server (16 processors, TeraBytes of RAM, RAID hard drives etc.)  What we are experiencing is that a couple queries, just take a lot of processor usage. We don't mind the query taking longer, but when the amount of processor usage goes too high, the server freezes.

 We have optimized the queries, but I wanted to ask if there is a way to set the maximum amount of processor usage.  We would like the query to be stopped or take more time, if a query attempts to go over the set amount of processor usage.

At this point, we are only looking at ways to change the configuration of the MS SQL Server and not the queries (the query is already optimized).  Could you please let me know a way to do this?

Answer : Set Maximum Processor Usage

> It would be ideal to have it limit the amount of processor % for each individual query.

It's not a limit on the % processor time, but you can use it to, for example, restrict any individual query from using more than 4 (or 2, or 1, or 8, ...) CPUs at once.  


> How can [MAXDOP] be configured.

You have the three options that I mentioned earlier.  Here are some more details about each of them:
1. Modify the query to add a MAXDOP query hint.  For example, this will retrict the query to using no more than a single CPU at one time:
      SELECT * FROM mytable
      INNER JOIN ...
      WHERE col1 = 'XYZ' AND ...
      OPTION (MAXDOP 1)

2. Create a plan guide for the query to apply this hint automatically, without needing to change the query text.

3. Set the sp_configure 'max degree of parallelism' configuration option to implement the restriction across all queries on the instance.  For example, this will prevent any individual query from using more than 4 CPUs at once:
      EXEC sp_configure 'max degree of parallelism', 4
      RECONFIGURE

Plan guides can be a bit tedious to set up correctly, so if you can, I would consider #1 and #3 before investigating alternative #2.


> we are seeing processor spikes, could this be caused by I/O problem
Slow I/O wouldn't cause CPU spikes, but it is possible that the same query that causes increased CPU usage also drives increased I/O, and it is possible that the I/O is a bigger bottleneck than the CPU.  We don't have any data here that proves or disproves this, but it's worth mentioning since it sounds like so far you have only looked at CPU.  Anyway, if your overall CPU (average across all processors) is >80% for a sustained period of time (not a little 1 second spike) then it's reasonable to look at CPU as a likely bottleneck.  If that's the situation, then I would look at CPU first and push any investigation into disk speek to the back burner.  

(Full disclosure: You may have noticed that I referred to a restriction on the number of CPUs used per "query operator" in the prior post.  Strictly speaking, this isn't quite the same thing as restricting the # of CPUs per *query*, but the different is so subtle that it's more or less an academic distinction in most cases.)
Random Solutions  
 
programming4us programming4us