请在与 Datasette 相同的环境中安装此插件。
datasette install datasette-gunicorn
此插件添加了一个新的 datasette gunicorn
命令。此命令接受大部分与 datasette serve
相同的选项,另外还有一个用于设置 Gunicorn worker 数量的选项:
-w/--workers X
- 设置 worker 数量。默认为 1。
要使用 4 个 worker 启动数据库服务,请运行以下命令:
datasette gunicorn fixtures.db -w 4
建议将您的 datasette 切换到 WAL 模式,以获得此配置的最佳性能
sqlite3 fixtures.db 'PRAGMA journal_mode=WAL;'
运行 datasette gunicorn --help
以获取完整的选项列表(与 datasette serve --help
相同,并新增了 -w
选项)。
并非所有 datasette serve
的选项都受支持。以下是可用选项的完整列表:
Usage: datasette gunicorn [OPTIONS] [FILES]...
Start a Gunicorn server running to serve Datasette
Options:
-i, --immutable PATH Database files to open in immutable mode
-h, --host TEXT Host for server. Defaults to 127.0.0.1 which
means only connections from the local machine
will be allowed. Use 0.0.0.0 to listen to all
IPs and allow access from other machines.
-p, --port INTEGER RANGE Port for server, defaults to 8001. Use -p 0 to
automatically assign an available port.
[0<=x<=65535]
--cors Enable CORS by serving Access-Control-Allow-
Origin: *
--load-extension PATH:ENTRYPOINT?
Path to a SQLite extension to load, and
optional entrypoint
--inspect-file TEXT Path to JSON file created using "datasette
inspect"
-m, --metadata FILENAME Path to JSON/YAML file containing
license/source metadata
--template-dir DIRECTORY Path to directory containing custom templates
--plugins-dir DIRECTORY Path to directory containing custom plugins
--static MOUNT:DIRECTORY Serve static files from this directory at
/MOUNT/...
--memory Make /_memory database available
--config CONFIG Deprecated: set config option using
configname:value. Use --setting instead.
--setting SETTING... Setting, see
docs.datasette.io/en/stable/settings.html
--secret TEXT Secret used for signing secure values, such as
signed cookies
--version-note TEXT Additional note to show on /-/versions
--help-settings Show available settings
--create Create database files if they do not exist
--crossdb Enable cross-database joins using the /_memory
database
--nolock Ignore locking, open locked files in read-only
mode
-w, --workers INTEGER Number of Gunicorn workers [default: 1]
--help Show this message and exit.
要在本地设置此插件,首先签出代码。然后创建一个新的虚拟环境:
cd datasette-gunicorn
python3 -m venv venv
source venv/bin/activate
现在安装依赖项和测试依赖项:
pip install -e '.[test]'
运行测试:
pytest