aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-04-26 17:56:57 +0200
committerDaniel Schadt <kingdread@gmx.de>2023-04-26 17:56:57 +0200
commitf7fce26deacf8b63b4852c511eb9cf460df694f9 (patch)
tree996f73110fc0c3b53fbd38983d64eacd25a0f0fe
parentbed7fb49b476db831c8d65ea1689ee89b9a0e369 (diff)
downloadfietsboek-f7fce26deacf8b63b4852c511eb9cf460df694f9.tar.gz
fietsboek-f7fce26deacf8b63b4852c511eb9cf460df694f9.tar.bz2
fietsboek-f7fce26deacf8b63b4852c511eb9cf460df694f9.zip
allow number of hittekaart threads to be limited
-rw-r--r--doc/administration/configuration.rst7
-rw-r--r--fietsboek/config.py6
-rw-r--r--fietsboek/scripts/fietscron.py13
-rw-r--r--fietsboek/scripts/fietsctl.py5
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}")