From 7944a8b0de9f892713da9d31ef0085cd9bcc5ff3 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 26 May 2018 17:43:22 -0700 Subject: [PATCH] Added num_sql_threads config option, closes #285 --- datasette/app.py | 9 ++++++--- docs/config.rst | 9 +++++++++ tests/test_api.py | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index b048c67e..b512fdb5 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -59,6 +59,9 @@ CONFIG_OPTIONS = ( ConfigOption("max_returned_rows", 1000, """ Maximum rows that can be returned from a table or custom query """.strip()), + ConfigOption("num_sql_threads", 3, """ + Number of threads in the thread pool for executing SQLite queries + """.strip()), ConfigOption("sql_time_limit_ms", 1000, """ Time limit for a SQL query in milliseconds """.strip()), @@ -124,7 +127,6 @@ class Datasette: def __init__( self, files, - num_threads=3, cache_headers=True, cors=False, inspect_data=None, @@ -136,8 +138,6 @@ class Datasette: config=None, ): self.files = files - self.num_threads = num_threads - self.executor = futures.ThreadPoolExecutor(max_workers=num_threads) self.cache_headers = cache_headers self.cors = cors self._inspect = inspect_data @@ -148,6 +148,9 @@ class Datasette: self.plugins_dir = plugins_dir self.static_mounts = static_mounts or [] self.config = dict(DEFAULT_CONFIG, **(config or {})) + self.executor = futures.ThreadPoolExecutor( + max_workers=self.config["num_sql_threads"] + ) self.max_returned_rows = self.config["max_returned_rows"] self.sql_time_limit_ms = self.config["sql_time_limit_ms"] self.page_size = self.config["default_page_size"] diff --git a/docs/config.rst b/docs/config.rst index a8b466a5..25bfd3d5 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -38,6 +38,15 @@ You can increase or decrease this limit like so:: datasette mydatabase.db --config max_returned_rows:2000 +num_sql_threads +--------------- + +Maximum number of threads in the thread pool Datasette uses to execute SQLite queries. Defaults to 3. + +:: + + datasette mydatabase.db --config num_sql_threads:10 + allow_facet ----------- diff --git a/tests/test_api.py b/tests/test_api.py index 1ec50b09..455ff864 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -940,6 +940,7 @@ def test_config_json(app_client): "suggest_facets": True, "allow_sql": True, "default_cache_ttl": 365 * 24 * 60 * 60, + "num_sql_threads": 3, } == response.json