From c3e6dcd1eb06dcd0454a4bf94d56bdafbb9fb668 Mon Sep 17 00:00:00 2001 From: krateng Date: Sat, 12 Mar 2022 08:28:48 +0100 Subject: [PATCH] More logging and documentation --- README.md | 16 ++++------------ maloja/database/dbcache.py | 2 +- maloja/database/jinjaview.py | 8 ++++++++ maloja/proccontrol/profiler.py | 4 +++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1a0562e..5f083f9 100644 --- a/README.md +++ b/README.md @@ -55,25 +55,17 @@ Maloja should run on any x86 or ARM machine that runs Python. I can support you with issues best if you use **Alpine Linux**. -Your CPU should have a single core passmark score of at the very least 1500. When virtualizing or containerizing, Maloja does not benefit from multiple assigned cores. - -500 MB RAM should give you a decent experience, but performance will benefit greatly from up to 2 GB. +Your CPU should have a single core passmark score of at the very least 1500. 500 MB RAM should give you a decent experience, but performance will benefit greatly from up to 2 GB. ### PyPI -You can download one of the included scripts in the `install` folder and run it with e.g. - -```console - sh install_alpine.sh -``` - -You can also simply call the install command +You can install Maloja with ```console pip install malojaserver ``` -directly - make sure you have all the system packages installed. +To make sure all dependencies are installed, you can also use one of the included scripts in the `install` folder. ### From Source @@ -102,7 +94,7 @@ Of note are these settings which should be passed as environmental variables to * Mount a [volume](https://docs.docker.com/engine/reference/builder/#volume) to the specified directory to access these files outside the container (and to make them persistent) * `MALOJA_FORCE_PASSWORD` -- Set an admin password for maloja -You must publish a port on your host machine to bind to the container's web port (default 42010). Note that the Docker version uses IPv4 per default. +You must publish a port on your host machine to bind to the container's web port (default 42010). The Docker version uses IPv4 per default. An example of a minimum run configuration to access maloja via `localhost:42010`: diff --git a/maloja/database/dbcache.py b/maloja/database/dbcache.py index 77dc2e3..b01c4f8 100644 --- a/maloja/database/dbcache.py +++ b/maloja/database/dbcache.py @@ -32,7 +32,7 @@ def maintenance(): trim_cache() def print_stats(): - log(f"Cache Size: {len(cache)}, System RAM Utilization: {psutil.virtual_memory().percent}%, Cache Hits: {hits}/{hits+misses}") + log(f"Cache Size: {len(cache)+len(entitycache)}, System RAM Utilization: {psutil.virtual_memory().percent}%, Cache Hits: {hits}/{hits+misses}") #print("Full rundown:") #import sys #for k in cache.keys(): diff --git a/maloja/database/jinjaview.py b/maloja/database/jinjaview.py index 409a309..ab19e73 100644 --- a/maloja/database/jinjaview.py +++ b/maloja/database/jinjaview.py @@ -5,6 +5,8 @@ from .dbcache import serialize from ..globalconf import malojaconfig +from doreah.logging import log + # this is a wrapper object that provides a DB connection so that one jinja page # (with all its included partials) can use it for all functions @@ -14,11 +16,15 @@ from ..globalconf import malojaconfig class JinjaDBConnection: def __init__(self): self.cache = {} + self.hits = 0 + self.misses = 0 def __enter__(self): self.conn = engine.connect() return self def __exit__(self, exc_type, exc_value, exc_traceback): self.conn.close() + log(f"Generated page with {self.hits}/{self.hits+self.misses} local Cache hits",module="debug_performance") + del self.cache def __getattr__(self,name): originalmethod = getattr(database,name) @@ -29,8 +35,10 @@ class JinjaDBConnection: if malojaconfig['USE_REQUEST_CACHE']: cachekey = serialize((id(originalmethod),kwargs)) if cachekey in self.cache: + self.hits += 1 return self.cache[cachekey] else: + self.misses += 1 result = originalmethod(**kwargs,dbconn=self.conn) self.cache[cachekey] = result return result diff --git a/maloja/proccontrol/profiler.py b/maloja/proccontrol/profiler.py index d7efdcb..3a98d35 100644 --- a/maloja/proccontrol/profiler.py +++ b/maloja/proccontrol/profiler.py @@ -23,11 +23,13 @@ def profile(func): profiler.enable() result = func(*args,**kwargs) profiler.disable() + + log(f"Executed {func.__name__} ({args}, {kwargs}) in {clock.stop():.2f}s",module="debug_performance") try: pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats")) except: pass - log(f"Executed {func.__name__} ({args}, {kwargs}) in {clock.stop():.5f}s",module="debug_performance") + return result return newfunc