#Sessions not expired?

17 messages · Page 1 of 1 (latest)

mental nymph
#

Hi all, a question: I have the sessions table that has grown to 32 million records. The lifetime is set to 2 weeks but I have sessions of more than 2 months. Shouldn`t they delete themselves?

solemn dragon
#

In config/session.php, there is a setting for the Session Sweeping Lottery, what's your value there?

solemn dragon
#

Alright, so that should fire off the following command for 2 % of the requests:

#

$this->getQuery()->where('last_activity', '<=', $this->currentTime() - $lifetime)->delete();

#

Since the table is so large, that SQL statement might be problematic. But the question is why it grew large in the first place (i.e. why the sweeping didn't do its job continuously)

#

If it's trying to run that query and it's slow, you should be getting really slow requests 2 % of the time. Last time I used the database session driver, I added a scheduled command to clean up old sessions instead and disabled the lottery

mental nymph
#

So do you think is only database-related? I can also switch to Redis istance

solemn dragon
#

I would want to find out if the session sweeping is running at all, or why not

#

Redis is certainly usually a preferred choice for sessions, but I'm more interested in understanding the problem here than just switch to solve it

#

Note that if you switch, all sessions will be invalidated

mental nymph
solemn dragon
#

Understandable of course. But can't you run some manual queries to clean up some table rows?

mental nymph
#

yes I just launched it, let's see how long it takes 😄

solemn dragon
#

You might want to try with some LIMIT first, as the deletion might lock the table

#

I suppose you have an index on last_activity?

mental nymph
#

yep