3

I just started using yii\web\DbSession for session storage, my current table has 33,000 rows in it.

Do I need all these records? Am I using them? Should I be setting up some sort of implementation that deletes all old records?

Khalid Al-Mutawa
  • 829
  • 1
  • 9
  • 16
  • 2
    Configure timeout. From yii documentation: `The number of seconds after which data will be seen as 'garbage' and cleaned up.` So you don't need to implement deleting, its already there. If you have performance issues - switch session from `db` to `memcache` or `redis`. – ineersa Dec 16 '15 at 11:00
  • Real question is - why did you opt for relational database as session storage? – Mjh Dec 16 '15 at 12:24
  • @Mjh On development server or local machine it's ok if you are lazy to install memcache or redis. But on production - yes its bad idea. – ineersa Dec 16 '15 at 14:36
  • @ineersa Is it really that bad? I have zero experience with Redis, I was following the Yii guide on https://github.com/yiisoft/yii2/blob/master/docs/guide/tutorial-performance-tuning.md – Khalid Al-Mutawa Dec 16 '15 at 20:56
  • @KhalidAl-Mutawa actually you don't need any experience with it. Just install it and use appropriate class from yii. It's already done for you. – ineersa Dec 17 '15 at 07:11
  • @ineersa should I install on a separate server or same server as my current mysql database? What's the best practice? – Khalid Al-Mutawa Dec 17 '15 at 07:15
  • @KhalidAl-Mutawa best will be to install it on some caching server, but you can install it on your mysql server too. Lower cost and way higher performance then you got now. Also you can do caching then in your application. – ineersa Dec 17 '15 at 07:18
  • @ineersa Thanks for the help! – Khalid Al-Mutawa Dec 17 '15 at 07:21

1 Answers1

6

It seems, you have a big project, so you have many user sessions. Having big table full of sessions itself is not a problem. Yii DbSession component has a garbage collector method gcSession() that is called on each session save and Yii takes care about expired records in sessions table automatically.

So yes, you need all of them.

If is slows your application, you might need to tune your DBMS. There is a good answer with useful links: MySQL optimization of huge table

Community
  • 1
  • 1
SilverFire
  • 1,582
  • 13
  • 22