Skip to content
Snippets Groups Projects
Commit 3ac41f2e authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

Task #11188: performance boost in writing cache to disk. Side effect: speeds...

Task #11188: performance boost in writing cache to disk. Side effect: speeds up scheduling and webscheduler
parent 7e9bb66a
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,6 @@ import ast ...@@ -11,7 +11,6 @@ import ast
from optparse import OptionParser from optparse import OptionParser
from threading import Thread, RLock from threading import Thread, RLock
import os.path import os.path
from pprint import pformat
from lofar.messaging import EventMessage, ToBus from lofar.messaging import EventMessage, ToBus
from lofar.common.util import humanreadablesize from lofar.common.util import humanreadablesize
...@@ -73,6 +72,7 @@ class CacheManager: ...@@ -73,6 +72,7 @@ class CacheManager:
self._cacheLock = RLock() self._cacheLock = RLock()
self._cache = {'path_du_results': {}, 'otdb_id2path': {} } self._cache = {'path_du_results': {}, 'otdb_id2path': {} }
self._last_cache_write_timestamp = datetime.datetime(1970, 1, 1)
self._readCacheFromDisk() self._readCacheFromDisk()
self.disk_usage = DiskUsage(mountpoint=mountpoint, self.disk_usage = DiskUsage(mountpoint=mountpoint,
...@@ -111,11 +111,16 @@ class CacheManager: ...@@ -111,11 +111,16 @@ class CacheManager:
def _writeCacheToDisk(self): def _writeCacheToDisk(self):
try: try:
tmp_path = '/tmp/tmp_storagequery_cache.py' if datetime.datetime.utcnow() - self._last_cache_write_timestamp > datetime.timedelta(minutes=5):
with open(tmp_path, 'w') as file: tmp_path = '/tmp/tmp_storagequery_cache.py'
cache_str = ''
with self._cacheLock: with self._cacheLock:
file.write(pformat(self._cache) + '\n') cache_str = str(self._cache)
os.rename(tmp_path, self._cache_path)
with open(tmp_path, 'w') as file:
file.write(cache_str)
os.rename(tmp_path, self._cache_path)
self._last_cache_write_timestamp = datetime.datetime.utcnow()
except Exception as e: except Exception as e:
logger.error("Error while writing du cache: %s", e) logger.error("Error while writing du cache: %s", e)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment