From 1b14770a50c4838452cbac7f3008bbf828629aa1 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Fri, 24 Feb 2023 05:14:40 +0100 Subject: [PATCH] Multiprocessing adjustments and optimizations. (0.21.3) --- README.md | 11 ++++------- bin/linspector | 5 +++-- linspector/linspector.py | 11 ++++++++--- requirements.txt | 3 ++- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 27da90b..7f9c51b 100644 --- a/README.md +++ b/README.md @@ -72,12 +72,9 @@ function / method. Currently, the Linspector core requires the following 3rd party libraries: -- [APScheduler](https://pypi.org/project/APScheduler/)- Apscheduler is the scheduler used in -Linspector for the execution of monitors. I started -to use this library in very early versions of Linspector in 2011. Since the main task -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 +- [APScheduler](https://pypi.org/project/APScheduler/)- APScheduler is a Python library that lets you +schedule your Python code to be executed later, either just once or periodically. +- [Loguru](https://pypi.org/project/loguru/) - Linspector uses Loguru for all logging stuff. Loguru is a library which aims to bring enjoyable logging in Python. ### Other used libraries @@ -182,7 +179,7 @@ Linspector is open-source and completely free and will always be. ### 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 of this software and associated documentation files (the "Software"), to deal diff --git a/bin/linspector b/bin/linspector index f8944a0..dd1f84a 100755 --- a/bin/linspector +++ b/bin/linspector @@ -11,13 +11,14 @@ import argparse import signal import sys +from loguru import logger + from linspector.configuration import Configuration from linspector.environment import Environment from linspector.linspector import Linspector from linspector.monitors import Monitors -from loguru import logger -__version__ = '0.21.2' +__version__ = '0.21.3' __author__ = 'Johannes Findeisen ' diff --git a/linspector/linspector.py b/linspector/linspector.py index 46e8470..f3b0ffb 100644 --- a/linspector/linspector.py +++ b/linspector/linspector.py @@ -11,6 +11,7 @@ import random from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor from apscheduler.jobstores.memory import MemoryJobStore from apscheduler.schedulers.background import BackgroundScheduler +from pytz import utc 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') == 'process': executors = { - 'default': ProcessPoolExecutor(int(configuration.get_option('linspector', - 'max_processes'))) + 'default': ThreadPoolExecutor( + int(configuration.get_option('linspector', 'max_threads'))), + 'processpool': ProcessPoolExecutor( + int(configuration.get_option('linspector', 'max_processes'))) } job_defaults = { + 'coalesce': True, # every scheduler job (monitor) must only exist once. 'max_instances': 1 } self.__scheduler['linspector'] = BackgroundScheduler(jobstores=jobstores, executors=executors, - job_defaults=job_defaults) + job_defaults=job_defaults, + timezone=utc) start_date = datetime.datetime.now() log.debug(monitors.get_monitors()) diff --git a/requirements.txt b/requirements.txt index b3b9967..d004b8e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,10 +7,11 @@ paramiko==3.0.0 pydantic==1.10.5 pysnmp==4.4.12 python-gammu==3.2.4 +pytz~=2022.7.1 requests==2.28.2 rich==13.3.1 syslog2==0.5.0 textual==0.11.1 typer==0.7.0 uvicorn==0.20.0 -xmpp2==0.4 \ No newline at end of file +xmpp2==0.4