clear sessions table

Posted By SAbow Tue 6 Mar 2018
Add to Favorites0
Author Message
SAbow
 Posted Tue 6 Mar 2018
Supreme Being

Supreme Being - (45,147 reputation)Supreme Being - (45,147 reputation)Supreme Being - (45,147 reputation)Supreme Being - (45,147 reputation)Supreme Being - (45,147 reputation)Supreme Being - (45,147 reputation)Supreme Being - (45,147 reputation)Supreme Being - (45,147 reputation)Supreme Being - (45,147 reputation)

Group: Forum Members
Last Active: Tue 2 Feb 2021
Posts: 77, Visits: 334
My sessions table gets large enough to crash my site a little too often. I'd like to automatically clear my sessions table every few days - has anyone done this before?
Paul Marked As Answer
 Posted Fri 9 Mar 2018
große Käse

große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)

Group: Administrators
Last Active: Tue 10 Sep 2024
Posts: 807, Visits: 2,748
Yes, to clarify this change. There was a cleanup routine that ran on the sessions table which was triggered when each session started. On big sites, this could become slow, and would run often (each new session).

The solution did two things. First, it put an index on the dates fields in the sessions table:

/****** Improve cleanup of expired sessions ******/CREATE NONCLUSTERED INDEX [SESS_DateLastUpdated] ON [dbo].[tblKartrisSessions](	[SESS_DateLastUpdated] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]GO


This makes the deletion of expired sessions far quicker because it's deleting based on the date, and the index allows it to identify and find items by date much more quickly.

Secondly, we moved the cleanup sessions routine out of the session_start and into the application_start part of the global.asax. This way, the routine only runs occasionally, instead of many times a day. Because it only really needs to do an occasional clean up.


--
If my post solves your issue, can you 'Mark as Answer' so it's easier for other users to find in future.

If you would like to be informed of new features, new releases, developments and occasional special bonuses, please sign up to our mailing list: http://bit.ly/19sKMZb
Paul Marked As Answer
 Posted Thu 22 Mar 2018
große Käse

große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)große Käse - (509,308 reputation)

Group: Administrators
Last Active: Tue 10 Sep 2024
Posts: 807, Visits: 2,748
The default time in IIS to recycle an app pool is 1740 minutes, or 29 hours.

So assuming you've not changed anything, and your host hasn't, the application_start will be triggered every 29 hours anyway.


--
If my post solves your issue, can you 'Mark as Answer' so it's easier for other users to find in future.

If you would like to be informed of new features, new releases, developments and occasional special bonuses, please sign up to our mailing list: http://bit.ly/19sKMZb

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top