From f7fce26deacf8b63b4852c511eb9cf460df694f9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 26 Apr 2023 17:56:57 +0200 Subject: allow number of hittekaart threads to be limited --- doc/administration/configuration.rst | 7 +++++++ fietsboek/config.py | 6 ++++++ fietsboek/scripts/fietscron.py | 13 +++++++++++-- fietsboek/scripts/fietsctl.py | 5 ++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/doc/administration/configuration.rst b/doc/administration/configuration.rst index d272234..5be3537 100644 --- a/doc/administration/configuration.rst +++ b/doc/administration/configuration.rst @@ -227,6 +227,12 @@ empty, which means that Fietsboek will not generate any overlays on its own. You can add ``heatmap`` and/or ``tilehunter`` to generate those maps automatically. +By default, ``hittekaart`` will use as many threads as CPU cores are available. +This leads to the fastest heatmap generation, but might be undesired on shared +hosts that also have other services running. You can explicitely set a thread +count by setting ``hittekaart.threads``. A value of "0" is equivalent to the +default behavior. + .. note:: The ``hittekaart.autogenerate`` has no effect on the ``fietsctl @@ -245,5 +251,6 @@ An example configuration excerpt can look like this: hittekaart.bin = /usr/local/bin/hittekaart hittekaart.autogenerate = heatmap tilehunter + hittekaart.threads = 2 .. _hittekaart: https://gitlab.com/dunj3/hittekaart diff --git a/fietsboek/config.py b/fietsboek/config.py index 42d717c..88d79a3 100644 --- a/fietsboek/config.py +++ b/fietsboek/config.py @@ -201,6 +201,12 @@ class Config(BaseModel): hittekaart_autogenerate: PyramidList = Field([], alias="hittekaart.autogenerate") """Overlay maps to automatically generate.""" + hittekaart_threads: int = Field(0, alias="hittekaart.threads") + """Number of threads that hittekaart should use. + + Defaults to 0, which makes it use as many threads as there are CPU cores. + """ + @validator("session_key") def _good_session_key(cls, value): """Ensures that the session key has been changed from its default diff --git a/fietsboek/scripts/fietscron.py b/fietsboek/scripts/fietscron.py index b968a18..8116204 100644 --- a/fietsboek/scripts/fietscron.py +++ b/fietsboek/scripts/fietscron.py @@ -110,7 +110,14 @@ def run_hittekaart(engine: Engine, data_manager: DataManager, redis: Redis, conf for mode in modes: LOGGER.info("Generating %s for user %d (high-priority)", mode.value, user.id) - hittekaart.generate_for(user, session, data_manager, mode, exe_path=exe_path) + hittekaart.generate_for( + user, + session, + data_manager, + mode, + exe_path=exe_path, + threads=config.hittekaart_threads, + ) if had_hq_item: return @@ -131,7 +138,9 @@ def run_hittekaart(engine: Engine, data_manager: DataManager, redis: Redis, conf for mode in modes: LOGGER.info("Generating %s for user %d (low-priority)", mode.value, user.id) - hittekaart.generate_for(user, session, data_manager, mode, exe_path=exe_path) + hittekaart.generate_for( + user, session, data_manager, mode, exe_path=exe_path, threads=config.hittekaart_threads + ) def refill_queue(session: Session, redis: Redis): diff --git a/fietsboek/scripts/fietsctl.py b/fietsboek/scripts/fietsctl.py index 7f7170c..4255b18 100644 --- a/fietsboek/scripts/fietsctl.py +++ b/fietsboek/scripts/fietsctl.py @@ -253,6 +253,7 @@ def cmd_hittekaart( query = models.User.query_by_email(email) exe_path = env["request"].config.hittekaart_bin + threads = env["request"].config.hittekaart_threads with env["request"].tm: dbsession = env["request"].dbsession data_manager: DataManager = env["request"].data_manager @@ -275,7 +276,9 @@ def cmd_hittekaart( click.echo(f"Generating overlay maps for {user.name}...") for mode in modes: - hittekaart.generate_for(user, dbsession, data_manager, mode, exe_path=exe_path) + hittekaart.generate_for( + user, dbsession, data_manager, mode, exe_path=exe_path, threads=threads + ) click.echo(f"Generated {mode.value}") -- cgit v1.2.3