commit aa30db536537d1e6c52c4d408bb4c668a879e610
parent c1737d6042b556d0fcd36537bdfb66c6a069dbc2
Author: Florian Dold <florian@dold.me>
Date: Tue, 25 Feb 2025 17:43:13 +0100
make number of workers configurable
Diffstat:
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/talermerchantdemos/cli.py b/talermerchantdemos/cli.py
@@ -34,8 +34,7 @@ import gunicorn.app.base
LOGGER = logging.getLogger(__name__)
-def bindspec(config_filename, which_shop, port):
- config = TalerConfig.from_file(config_filename)
+def bindspec(config, which_shop, port):
confsection = f"frontend-demo-{which_shop}"
# Takes precedence.
@@ -55,7 +54,7 @@ def bindspec(config_filename, which_shop, port):
else port
)
if not port_launch:
- sys.stderr.write("Port number wasn't found in config and in arguments.")
+ print("Port number wasn't found in config and in arguments.", file=sys.stderr)
exit(1)
return dict(bind=f"0.0.0.0:{port_launch}")
@@ -65,8 +64,14 @@ def bindspec(config_filename, which_shop, port):
return dict(bind=f"unix:{path}", umask=mode)
-def number_of_workers():
- return (multiprocessing.cpu_count() * 2) + 1
+def number_of_workers(config, which_shop):
+ confsection = f"frontend-demo-{which_shop}"
+ nw = config[confsection]["num_workers"].value_int(required=False)
+ if nw is None:
+ # Be conservative with number of workers
+ return 2
+ else:
+ return nw
class StandaloneApplication(gunicorn.app.base.BaseApplication):
@@ -90,7 +95,7 @@ class StandaloneApplication(gunicorn.app.base.BaseApplication):
@click.command("Global shop launcher")
-@click.option("-c", "--config", help="Configuration file", required=False)
+@click.option("-c", "--config", 'config_filename', help="Configuration file", required=False)
@click.option(
"--http-port",
help="HTTP port to serve (if not given, serving comes from config)",
@@ -98,19 +103,19 @@ class StandaloneApplication(gunicorn.app.base.BaseApplication):
type=int,
)
@click.argument("which-shop")
-def demos(config, http_port, which_shop):
+def demos(config_filename, http_port, which_shop):
"""WHICH_SHOP is one of: blog, donations, provision, or landing."""
if which_shop not in ["blog", "donations", "provision", "landing"]:
print("Please use a valid shop name: blog, donations, provision, landing.")
sys.exit(1)
-
+ config = TalerConfig.from_file(config_filename)
options = {
- "workers": number_of_workers(),
+ "workers": number_of_workers(config, which_shop),
**bindspec(config, which_shop, http_port),
}
mod = f"talermerchantdemos.{which_shop}"
- os.environ["TALER_CONFIG_FILENAME"] = config or ""
+ os.environ["TALER_CONFIG_FILENAME"] = config_filename or ""
app = importlib.import_module(mod).app
StandaloneApplication(app, options).run()