Should I run sessions2trash.py even if I use Redis for sessions and set an expiration time?

139 views
Skip to first unread message

Lisandro

unread,
Jul 26, 2022, 7:40:04 AM7/26/22
to web2py-users
Hey there! 
I'm using Redis to store sessions. Every session has an expiration time of two days. Should I still run sessions2trash.py from time to time?
The answer is not clear to me. The documentation says:

If session_expiry is not set, sessions will be handled as usual, you'd need to cleanup sessions as usual once a while.
However, when session_expiry is set will delete automatically sessions after n seconds (e.g. if set to 3600, session will expire exactly one hour later having been updated the last time), you should occasionally run sessions2trash.py just to clean the key holding the set of all the sessions previously issued.

If the answer is affirmative:
 - How frequently should I run sessions2trash.py? 
 - If my web2py instance runs several applications, lets say, a thousand apps, will I have to run sessions2trash.py a thousand times, one time for each app?

Thanks in advance!
Warm regards,
Lisandro 

Lisandro

unread,
Aug 6, 2022, 6:56:41 AM8/6/22
to web2py-users
I'll try to answer my own question, in case it helps someone else.
Yes, you should run sessions2trash periodically, even if you're using Redis and you're setting an expiration time for every session.

As the documentation states: "... when session_expiry is set [...] you should ocassionally run sessions2trash.py just to clean the key holding the set of all the sessions previously issued..."

In my deployment I have around 1000 applications running in one web2py instance. All of them set session_expiry to 2 days. The load is very stable: about 2 millon sessions in memory, using about 1gb of memory. However, while the number of sessions stays stable in time, memory usage increases slowly. I've found that running sessions2trash makes memory usage to go down to 1gb. And yes, you have to run it once for every installed app. I've inspected the source code of sessions2trash.py and I can't realise what is it that it deletes (besides the expired sessions). 

It would be nice to have a script that only takes care of cleaning "the other stuff", so it doesn't take too much time to run. Consider that sessions2trash.py iterates over all the stored sessions, and if you're using Redis and you're setting an expiration time for every session, it doesn't make sense to iterate over all the dataset just to clean "that other stuff".

Hope it helps someone :)

Raul Monares

unread,
Aug 16, 2022, 7:22:47 PM8/16/22
to web2py-users
Thanks for sharing
Reply all
Reply to author
Forward
0 new messages