Multiprocessing adjustments and optimizations. (0.21.3)

This commit is contained in:
Johannes Findeisen 2023-02-24 05:14:40 +01:00
commit 1b14770a50
4 changed files with 17 additions and 13 deletions

View file

@ -72,12 +72,9 @@ function / method.
Currently, the Linspector core requires the following 3rd party libraries: Currently, the Linspector core requires the following 3rd party libraries:
- [APScheduler](https://pypi.org/project/APScheduler/)- Apscheduler is the scheduler used in - [APScheduler](https://pypi.org/project/APScheduler/)- APScheduler is a Python library that lets you
Linspector for the execution of monitors. I started schedule your Python code to be executed later, either just once or periodically.
to use this library in very early versions of Linspector in 2011. Since the main task - [Loguru](https://pypi.org/project/loguru/) - Linspector uses Loguru for all logging stuff. Loguru is a library
in Linspector is the execution of jobs in regularly intervals I believe it is the right
decision to make use of APScheduler directly in the core of the Linspector project.
- [Loguru](https://pypi.org/project/loguru/) - Linspector uses Loguru for file based logging. Loguru is a library
which aims to bring enjoyable logging in Python. which aims to bring enjoyable logging in Python.
### Other used libraries ### Other used libraries
@ -182,7 +179,7 @@ Linspector is open-source and completely free and will always be.
### MIT license ### MIT license
Copyright (c) 2013 - 2022 Johannes Findeisen Copyright (c) 2013 - 2023 Johannes Findeisen
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -11,13 +11,14 @@ import argparse
import signal import signal
import sys import sys
from loguru import logger
from linspector.configuration import Configuration from linspector.configuration import Configuration
from linspector.environment import Environment from linspector.environment import Environment
from linspector.linspector import Linspector from linspector.linspector import Linspector
from linspector.monitors import Monitors from linspector.monitors import Monitors
from loguru import logger
__version__ = '0.21.2' __version__ = '0.21.3'
__author__ = 'Johannes Findeisen <you@hanez.org>' __author__ = 'Johannes Findeisen <you@hanez.org>'

View file

@ -11,6 +11,7 @@ import random
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from apscheduler.jobstores.memory import MemoryJobStore from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from pytz import utc
def job_execution(log, monitor): def job_execution(log, monitor):
@ -64,16 +65,20 @@ class Linspector:
if configuration.get_option('linspector', 'scheduler_mode'): if configuration.get_option('linspector', 'scheduler_mode'):
if configuration.get_option('linspector', 'scheduler_mode') == 'process': if configuration.get_option('linspector', 'scheduler_mode') == 'process':
executors = { executors = {
'default': ProcessPoolExecutor(int(configuration.get_option('linspector', 'default': ThreadPoolExecutor(
'max_processes'))) int(configuration.get_option('linspector', 'max_threads'))),
'processpool': ProcessPoolExecutor(
int(configuration.get_option('linspector', 'max_processes')))
} }
job_defaults = { job_defaults = {
'coalesce': True,
# every scheduler job (monitor) must only exist once. # every scheduler job (monitor) must only exist once.
'max_instances': 1 'max_instances': 1
} }
self.__scheduler['linspector'] = BackgroundScheduler(jobstores=jobstores, self.__scheduler['linspector'] = BackgroundScheduler(jobstores=jobstores,
executors=executors, executors=executors,
job_defaults=job_defaults) job_defaults=job_defaults,
timezone=utc)
start_date = datetime.datetime.now() start_date = datetime.datetime.now()
log.debug(monitors.get_monitors()) log.debug(monitors.get_monitors())

View file

@ -7,10 +7,11 @@ paramiko==3.0.0
pydantic==1.10.5 pydantic==1.10.5
pysnmp==4.4.12 pysnmp==4.4.12
python-gammu==3.2.4 python-gammu==3.2.4
pytz~=2022.7.1
requests==2.28.2 requests==2.28.2
rich==13.3.1 rich==13.3.1
syslog2==0.5.0 syslog2==0.5.0
textual==0.11.1 textual==0.11.1
typer==0.7.0 typer==0.7.0
uvicorn==0.20.0 uvicorn==0.20.0
xmpp2==0.4 xmpp2==0.4