forked from rDrama/rDrama
Fix pruning of {SITE}_loggedin/out dicts.
For the past week, we noticed a gradual increase in CPU usage and request times. Use of a sampling profiler revealed the time waas spent in serializing/deserializing data stored in Redis. In particular, the user counter dicts were filtered for calculation of the loggedin/out counters, but the filtered versions were never stored. To make concurrency safe, we still filter on every request, but at least the resting data will eventually be appropriately filtered, and this data is non-critical regardless.master
parent
b6703595da
commit
683d562058
|
@ -52,9 +52,6 @@ def get_logged_in_user():
|
||||||
|
|
||||||
loggedin = cache.get(f'{SITE}_loggedin') or {}
|
loggedin = cache.get(f'{SITE}_loggedin') or {}
|
||||||
loggedout = cache.get(f'{SITE}_loggedout') or {}
|
loggedout = cache.get(f'{SITE}_loggedout') or {}
|
||||||
g.loggedin_counter = 0
|
|
||||||
g.loggedout_counter = 0
|
|
||||||
|
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
if v:
|
if v:
|
||||||
if session["session_id"] in loggedout: del loggedout[session["session_id"]]
|
if session["session_id"] in loggedout: del loggedout[session["session_id"]]
|
||||||
|
@ -69,12 +66,14 @@ def get_logged_in_user():
|
||||||
if 'spider' not in ua.lower() and 'bot' not in ua.lower():
|
if 'spider' not in ua.lower() and 'bot' not in ua.lower():
|
||||||
loggedout[session["session_id"]] = (timestamp, ua)
|
loggedout[session["session_id"]] = (timestamp, ua)
|
||||||
|
|
||||||
g.loggedin_counter = len([x for x in loggedin.values() if timestamp-x < LOGGEDIN_ACTIVE_TIME])
|
loggedin = {k: v for k, v in loggedin.items() if (timestamp - v) < LOGGEDIN_ACTIVE_TIME}
|
||||||
|
loggedout = {k: v for k, v in loggedout.items() if (timestamp - v[0]) < LOGGEDIN_ACTIVE_TIME}
|
||||||
cache.set(f'{SITE}_loggedin', loggedin)
|
cache.set(f'{SITE}_loggedin', loggedin)
|
||||||
|
|
||||||
g.loggedout_counter = len([x for x in loggedout.values() if timestamp-x[0] < LOGGEDIN_ACTIVE_TIME])
|
|
||||||
cache.set(f'{SITE}_loggedout', loggedout)
|
cache.set(f'{SITE}_loggedout', loggedout)
|
||||||
|
|
||||||
|
g.loggedin_counter = len(loggedin)
|
||||||
|
g.loggedout_counter = len(loggedout)
|
||||||
|
|
||||||
g.v = v
|
g.v = v
|
||||||
|
|
||||||
if v: v.poor = session.get('poor')
|
if v: v.poor = session.get('poor')
|
||||||
|
|
Loading…
Reference in New Issue