开发者

django cached session

I have two questions:

1) I am wondering whether using

django.contrib.sessions.backends.cache

for storing sessions really improves performance of a website? Assuming there are around 25k simultaneous users. Each user making many database changes (for example browser game). Is the difference even noticable?

2) Again while using cached session (without db): how to check whether given user is logged in (do not allow multiple logins on the same accou开发者_如何学JAVAnt)?


re 1.

from my experience difference is huge. in your scenario, every time session is created or changed - this will generate a db write. each time user is accessing a site - a db read will be generated. moving this out of the DB - saves at least one query per request.

this additional traffic, plus your normal app traffic may easily kill your db performance.

re. 2.

even for the db backed session there are no clear way to make sure that user is logged once (reading all session data, depickling it and then filtering is not a clear way :) )

to do this I'll probably use cache: each time user is logged in, check if here is a key (e.g. user:<user_id>) in the cache, stored value will be a session id, and if current session is different then stored one - expire old session, store new session id.

but even this one will not always work, sometimes browser tabs/windows share same cookies (especially when SESSION_EXPIRE_AT_BROWSER_CLOSE is False - default) and sessions are solely cookie based.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜