python - Why running django's session cleanup command kill's my machine resources? -
i have 1 year production site configured django.contrib.sessions.backends.cached_db
backend mysql dabatase backend. reason why choice cached_db mix of security read performance.
the problem is, cleanup command, responsible delete expired sessions, sadly never been executed, resuting in 2.3gb session table data length, 6 million rows , 500mb index length.
when try run ./manage.py cleanup
(in django 1.3) command, or ./manage.py clearsessions
(django`s 1.5 correspondent), process never ends (or patience doesn't complete 3 hours).
the code django use's is:
session.objects.filter(expire_date__lt=timezone.now()).delete()
in first impression, think that's normal because table has 6m rows, but, after inspect system's monitor, discover memory , cpu used python process, not mysqld, fullfilling machine's resources. think that's terrible wrong command code. seem's that's python iterate on founded expired sessions row before delete each of them, 1 one. in case, code refactoring raw delete from
command can resolve problem , helps django community, right? but, if case, queryset delete command acting weird , none optimized in opinion. right?
thanks
Comments
Post a Comment