1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

High RAM usage affects all caches

This commit is contained in:
Krateng 2020-06-05 13:20:54 +02:00
parent 813dee8400
commit 08fe4695f6
2 changed files with 4 additions and 4 deletions

View File

@ -5,7 +5,7 @@ author = {
"email":"maloja@krateng.dev", "email":"maloja@krateng.dev",
"github": "krateng" "github": "krateng"
} }
version = 2,4,9 version = 2,4,10
versionstr = ".".join(str(n) for n in version) versionstr = ".".join(str(n) for n in version)
links = { links = {
"pypi":"malojaserver", "pypi":"malojaserver",

View File

@ -1173,8 +1173,8 @@ def invalidate_caches():
log("Database caches invalidated.") log("Database caches invalidated.")
def reduce_caches(to=0.75): def reduce_caches(to=0.75):
global cache_query, cache_aggregate global cache_query, cache_aggregate, cache_query_perm, cache_aggregate_perm
for c in cache_query, cache_aggregate: for c in cache_query, cache_aggregate, cache_query_perm, cache_aggregate_perm:
currentsize = len(c) currentsize = len(c)
targetsize = int(currentsize * to) targetsize = int(currentsize * to)
c.set_size(targetsize) c.set_size(targetsize)
@ -1183,7 +1183,7 @@ def reduce_caches(to=0.75):
def reduce_caches_if_low_ram(): def reduce_caches_if_low_ram():
ramprct = psutil.virtual_memory().percent ramprct = psutil.virtual_memory().percent
if ramprct > cmp: if ramprct > cmp:
log("{prct}% RAM usage, reducing temporary caches!".format(prct=ramprct),module="debug") log("{prct}% RAM usage, reducing caches!".format(prct=ramprct),module="debug")
ratio = (cmp / ramprct) ** 3 ratio = (cmp / ramprct) ** 3
reduce_caches(to=ratio) reduce_caches(to=ratio)