More logging and documentation

This commit is contained in:
krateng 2022-03-12 08:28:48 +01:00
parent 634cb38dec
commit c3e6dcd1eb
4 changed files with 16 additions and 14 deletions

View File

@ -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**. 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. 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.
500 MB RAM should give you a decent experience, but performance will benefit greatly from up to 2 GB.
### PyPI ### PyPI
You can download one of the included scripts in the `install` folder and run it with e.g. You can install Maloja with
```console
sh install_alpine.sh
```
You can also simply call the install command
```console ```console
pip install malojaserver 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 ### 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) * 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 * `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`: An example of a minimum run configuration to access maloja via `localhost:42010`:

View File

@ -32,7 +32,7 @@ def maintenance():
trim_cache() trim_cache()
def print_stats(): 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:") #print("Full rundown:")
#import sys #import sys
#for k in cache.keys(): #for k in cache.keys():

View File

@ -5,6 +5,8 @@ from .dbcache import serialize
from ..globalconf import malojaconfig from ..globalconf import malojaconfig
from doreah.logging import log
# this is a wrapper object that provides a DB connection so that one jinja page # 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 # (with all its included partials) can use it for all functions
@ -14,11 +16,15 @@ from ..globalconf import malojaconfig
class JinjaDBConnection: class JinjaDBConnection:
def __init__(self): def __init__(self):
self.cache = {} self.cache = {}
self.hits = 0
self.misses = 0
def __enter__(self): def __enter__(self):
self.conn = engine.connect() self.conn = engine.connect()
return self return self
def __exit__(self, exc_type, exc_value, exc_traceback): def __exit__(self, exc_type, exc_value, exc_traceback):
self.conn.close() 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): def __getattr__(self,name):
originalmethod = getattr(database,name) originalmethod = getattr(database,name)
@ -29,8 +35,10 @@ class JinjaDBConnection:
if malojaconfig['USE_REQUEST_CACHE']: if malojaconfig['USE_REQUEST_CACHE']:
cachekey = serialize((id(originalmethod),kwargs)) cachekey = serialize((id(originalmethod),kwargs))
if cachekey in self.cache: if cachekey in self.cache:
self.hits += 1
return self.cache[cachekey] return self.cache[cachekey]
else: else:
self.misses += 1
result = originalmethod(**kwargs,dbconn=self.conn) result = originalmethod(**kwargs,dbconn=self.conn)
self.cache[cachekey] = result self.cache[cachekey] = result
return result return result

View File

@ -23,11 +23,13 @@ def profile(func):
profiler.enable() profiler.enable()
result = func(*args,**kwargs) result = func(*args,**kwargs)
profiler.disable() profiler.disable()
log(f"Executed {func.__name__} ({args}, {kwargs}) in {clock.stop():.2f}s",module="debug_performance")
try: try:
pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats")) pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats"))
except: except:
pass pass
log(f"Executed {func.__name__} ({args}, {kwargs}) in {clock.stop():.5f}s",module="debug_performance")
return result return result
return newfunc return newfunc