I am trying to tweak the stored procedure below as its called 30k times a minute on our website.
CREATE PROCEDURE [dbo].[mltHttpCallStatus]
@SupplierId AS INTEGER,
@CallIsGood AS BIT,
@MaxWorkerThreads AS INT,
@MaxIOThreads AS INT,
@AvailWorkerThreads AS INT,
@AvailIOThreads AS INT,
@ScriptTypeId AS INT,
@SiteTypeId AS VARCHAR(50),
@ConnectionTime AS INT,
@SiteName AS VARCHAR(50),
@HostName AS VARCHAR(50)
AS
--DEBUG BEN (Flight details keep failing) 07012008 19:30
--Return
SET NOCOUNT ON
DECLARE @GoodCalls AS INT,
@BadCalls AS INT
SET @BadCalls = 0
SET @GoodCalls = 0
IF @CallIsGood = 1
SET @GoodCalls = 1
ELSE
SET @BadCalls = 1
UPDATE HttpCallStatus_tbl SET
GoodCalls = GoodCalls + @GoodCalls,
BadCalls = BadCalls + @BadCalls,
TotalConnectionTime = TotalConnectionTime + @ConnectionTime
--WHERE dbo.datepart_fn(DayDate) = dbo.datepart_fn(getDate())
WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, DayDate)) = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
AND DATEPART(HOUR, DayDate) = DATEPART(HOUR, getDate())
AND SupplierId = @SupplierId
AND ScriptTypeId = @ScriptTypeId
AND SiteTypeId = @SiteTypeId
AND SiteName = @SiteName
AND HostName = @HostName
IF @@ROWCOUNT = 0
BEGIN
INSERT INTO HttpCallStatus_tbl (DayDate,SupplierId,GoodCalls,BadCalls,ScriptTypeId,SiteTypeId,TotalConnectionTime,
MaxWorkerThreads,MaxIOThreads,AvailWorkerThreads,AvailIOThreads,SiteName,HostName)
VALUES (CONVERT(DATETIME, getDate(), 103),
@SupplierId,
@GoodCalls,
@BadCalls,
@ScriptTypeId,
@SiteTypeId,
@ConnectionTime,
0,
0,
0,
0,
@SiteName,
@HostName)
END
table structure
Column_name Type Length
DayDate datetime 8
SupplierId int 4
GoodCalls int 4
BadCalls int 4
ScriptTypeId int 4
SiteTypeId varchar 50
TotalConnectionTime int 4
MaxWorkerThreads int 4
MaxIOThreads int 4
AvailWorkerThreads int 4
AvailIOThreads int 4
SiteName varchar 50
HostName varchar 50
SearchCount int 4
DomainId int 4
Indexes
[PK_HttpCallStatus_tbl] clustered, unique, primary key [DayDate],[SupplierId]
[IX_HttpCallStatus_tbl] nonclustered [SupplierId]
[idx_HttpCallStatus_tbl_1] nonclustered
[SupplierId], [ScriptTypeId], [SiteTypeId], [SiteName], [HostName]
, [DayDate], [GoodCalls], [BadCalls], [TotalConnectionTime]
I noticed these variables are unused @MaxWorkerThreads, @MaxIOThreads, @AvailWorkerThreads, @AvailIOThreads. also could make the variables @goodcalls & @Badcalls TINYINTS. I also noticed this conversion in the insert statement VALUES (CONVERT(DATETIME, getDate(), 103). but I think this is the default so could change to Getdate()
my issues is its hard to measure the improvements as they are both so quick, is it worth me making these changes, will I even see a small gain ?
DATE
column and a separateint
hours column and add an appropriate unique index.