Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

delete ASPStateTempSessions and blocking

$
0
0

Hi misters,

about DeleteExpiredSessions SP in ASPState dababase for delete ASPStateTempSessions.

aspnet 2.0

CREATEPROCEDURE[dbo].[DeleteExpiredSessions]
       AS
           DECLARE@nowdatetime
           SET@now=GETUTCDATE()
 
           DELETE dbo.ASPStateTempSessions
           WHEREExpires<@now
 

           RETURN

aspnet 4.0

IF(@ver>=8)
   SET@cmd=N'
        CREATE PROCEDURE dbo.DeleteExpiredSessions
        AS
            SET NOCOUNT ON
            SET DEADLOCK_PRIORITY LOW
 
            DECLARE @now datetime
            SET @now = GETUTCDATE()
 
            CREATE TABLE #tblExpiredSessions
            (
                SessionId nvarchar(88) NOT NULL PRIMARY KEY
            )
 
            INSERT #tblExpiredSessions (SessionId)
                SELECT SessionId
                FROM [DatabaseNamePlaceHolder].dbo.ASPStateTempSessions WITH (READUNCOMMITTED)
                WHERE Expires < @now
 
            IF @@ROWCOUNT <> 0
            BEGIN
                DECLARE ExpiredSessionCursor CURSOR LOCAL FORWARD_ONLY READ_ONLY
                FOR SELECT SessionId FROM #tblExpiredSessions
 
                DECLARE @SessionId nvarchar(88)
 
                OPEN ExpiredSessionCursor
 
                FETCH NEXT FROM ExpiredSessionCursor INTO @SessionId
 
                WHILE @@FETCH_STATUS = 0
                    BEGIN
                        DELETE FROM [DatabaseNamePlaceHolder].dbo.ASPStateTempSessions WHERE SessionId = @SessionId AND Expires < @now
                        FETCH NEXT FROM ExpiredSessionCursor INTO @SessionId
                    END
 
                CLOSE ExpiredSessionCursor
 
                DEALLOCATE ExpiredSessionCursor
 
            END
 
            DROP TABLE #tblExpiredSessions

RETURN 0'

Maybe problems using dbo.DeleteExpiredSessionsand procedure dbo.TempResetTimeout?

However, the problem is that as session size grows, each delete takes longer and as the number of sessions grows, this simple DELETE ends up causing substantial blocking. It was at the head of nearly every blocking chain. This proc is run every five minutes. There is no need for this proc to do all the deletes in a single operation. I replaced it with one that does a series of individual deletes

Every time a page is loaded (and, if the web app hasn't been created correctly, possibly multiple times per page load), the stored procedure dbo.TempResetTimeout is called, ensuring that the timeout for that particular session is extended as long as they continue to generate activity. On a busy web site, this can cause a very high volume of update activity against the table dbo.ASPStateTempSessions

this page 2013/01/t-sql-queries/optimize-aspstate in  sql performance

/greglow/2007/02/04/improving-asp-net-session-state-database-performance-by-reducing-blocking/#comment-1199 in blogs msmvps com




Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>