Quantcast
Channel: Aneef.Net » SQL
Viewing all articles
Browse latest Browse all 7

100 % CPU SQL Server 2005, Server crashes!

$
0
0

Ah back to my blog. well these days I’m on holidays for Sinhala/ Tamil New year in Sri Lanka. so anyway let met start with wishing all Sinhala  and Tamil Friends A HAPPY NEW YEAR.

Lets get back to business, its been a long time since my last post, as usual busy schedules (i know, i know i tell this often !), but all these days i had several bits and pieces on queue for my blog, and here i am with that.

Last week i had an early morning call from Administrators of  Catalogues4u.com.au. they said that the website is running very slow, and users are having connection timeouts in their browsers or poor performance, server logs are filled with SQLConnection Timeout. they have been receiving calls, complaints from their top management, and most of all server restarts. horrible isn’t it?  they have checked the server, and the CPU was running almost 100%, and the culprit which used the most of the CPU was SQL Server.

After spending time in logs, and SQL profiler runs, i found that one stored procedure was taking more time to execute than the others.

here is a part of that SP:

SELECT  DISTINCT c.ENDDATE,c.ID, c.NAME,c.THUMBNAILURL,c.CONTENSDESCRIPTION
INTO #temp
FROM GW_CATELOGUE c
 INNER JOIN dbo.GW_CATELOGUE_POSTCODES cp
  ON c.ID=cp.CATELOGUEID
 INNER JOIN dbo.GW_POSTCODES p ON p.Id=cp.POSTCODEID
WHERE  p.POSTCODE=@postcode
 AND (ENDDATE BETWEEN getDate() AND DATEADD(dd, 7, getDate()))
 AND (STARTDATE <= getDate())
 AND (ENDDATE >= getDate())
 AND c.APPROVED=1 ORDER BY c.ENDDATE

There were some other SP’s with same structure except the  below Date Filtering which were running perfectly alright:

AND (ENDDATE BETWEEN getDate() AND DATEADD(dd, 7, getDate()))
AND (STARTDATE <= getDate()) AND (ENDDATE >= getDate())

Well This made me thing something is fishy with the date. with confused mind, and help of MVP Dinesh Priyangara I Created 4 Non- Clustered Indexes on Catalogue_STARTDATE, Catalogue_ENDDATE and POSTCODE:

CREATE INDEX Catalogue_STARTDATE ON GW_CATELOGUE(STARTDATE)
CREATE INDEX Catalogue_ENDDATE ON GW_CATELOGUE(ENDDATE)
CREATE INDEX PostCodes_POSTCODE ON GW_POSTCODES(POSTCODE)

And Bang!! it worked. server  was back to normal, and everyone was happy. well this might not be a big deal, but still as somebody said, information is wealth!!.






Viewing all articles
Browse latest Browse all 7

Trending Articles