Skip to content

Commit c7bc9e4

Browse files
committed
Update chat docs & resource limits
1 parent 2a7e677 commit c7bc9e4

File tree

8 files changed

+56
-18
lines changed

8 files changed

+56
-18
lines changed

docs/install_setup/chat.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ If the model is not present in the local cache, it will be downloaded when Gramp
5252

5353
Please share learnings about different models with the community!
5454

55+
!!! info
56+
The sentence transformers library consumes a significant amount of memory, which might cause worker processes being killed. As a rule of thumb, with semantic search enabled, each Gunicorn worker consumes around 200 MB of memory and each celery worker around 500 MB of memory even when idle, and up to 1 GB when computing embeddings. See [Limit CPU and memory usage](cpu-limited.md) for settings that limit memory usage. In addition, it is advisable to provision a sufficiently large swap partition to prevent OOM errors due to transient memory usage spikes.
57+
5558
## Setting up an LLM provider
5659

5760
Communication with the LLM uses an OpenAI compatible API using the `openai-python` library. This allows using a locally deployed LLM via Ollama (see [Ollama OpenAI compatibility](https://ollama.com/blog/openai-compatibility)) or an API like OpenAI or Huggingface TGI. The LLM is configured via the configuration parameters `LLM_MODEL` and `LLM_BASE_URL`.

docs/install_setup/cpu-limited.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
1-
# Limit CPU usage
1+
# Limit CPU and memory usage
22

3-
In order to avoid high CPU/RAM usage, it is possible to set the number of workers
4-
using the environment variable `GUNICORN_NUM_WORKERS`.
3+
In the recommended docker-based setup, Gramps Web uses [Gunicorn](https://gunicorn.org/) to serve the
4+
backend and [Celery](https://docs.celeryq.dev) for background tasks. In both cases, several worker
5+
processes can be run in parallel, which makes the application more responsive from a user perspective.
6+
However, increasing the number of workers also increase the amount of RAM used (even when the application is idle)
7+
and allowing requests to be processed in parallel can lead to high CPU usage (in particular when many users
8+
are using the application simultaneously). Both Gunicorn and Celery allow to limit the number of parallel workers.
59

6-
Here, we will take a number of workers = 2. Adjust it according to your needs.
7-
It may be a good idea to check the CPU/Threads available before choosing the value:
10+
## Get information about your system
811

9-
> lscpu | grep CPU
12+
On Linux, you can check the number of cores available on your system with the following command:
1013

11-
The easiest way is to declare the variable in the `docker-compose.yml` file,
12-
under the "environment".
14+
```bash
15+
lscpu | grep CPU
16+
```
1317

18+
To see how much memory and swap space you have available, use
19+
20+
```bash
21+
free -h
1422
```
15-
version: "3.7"
23+
24+
25+
## Limiting the number of Gunicorn workers
26+
27+
The easiest way to set the number of Gunicorn workers when using the default Gramps Web
28+
docker image is to set the environment variable `GUNICORN_NUM_WORKERS`, e.g. by declaring it
29+
in the `docker-compose.yml` file,
30+
under the "environment".
31+
32+
```yaml
1633
services:
1734
grampsweb:
1835
environment:
1936
GUNICORN_NUM_WORKERS: 2
2037
```
2138
22-
Other ways are possible, for example by storing the variable in a file,
23-
and calling it in the startup command:
39+
See [the Gunicorn documentation](https://docs.gunicorn.org/en/stable/design.html#how-many-workers) to decide
40+
about the ideal number of workers.
41+
42+
43+
44+
## Limiting the number of Celery workers
45+
46+
To set the number of Celery workers, adapt the `concurrency` setting in the Docker compose file:
47+
48+
```yaml
49+
grampsweb_celery:
50+
command: celery -A gramps_webapi.celery worker --loglevel=INFO --concurrency=2
51+
```
2452

25-
> docker compose --env-file ./env up
53+
See [the Celery documentation](https://docs.celeryq.dev/en/stable/userguide/workers.html#concurrency) to decide
54+
about the ideal number of workers.
2655

27-
In this case, the `env` file would contain a single line: GUNICORN_NUM_WORKERS=2
56+
!!! info
57+
If the `concurrency` flag is omitted (which was the case in the Gramps Web documentation until v2.5.0), it
58+
defaults to the number of CPU cores available on the system, which might consume a substantial amount of memory.

docs/user-guide/chat.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Using AI chat
22

3+
!!! info
4+
AI chat requires Gramps Web API version 2.5.0 or higher and Gramps Web version 24.10.0 or higher.
5+
6+
37
The chat view in Gramps Web (if available in your installation) gives access to an AI assistant that can answer questions about your family tree.
48

59
!!! warning

examples/caprover-one-click-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ services:
4949
notExposeAsWebApp: 'true'
5050
dockerfileLines:
5151
- FROM ghcr.io/gramps-project/grampsweb:$$cap_version
52-
- CMD exec celery -A gramps_webapi.celery worker --loglevel=INFO
52+
- CMD exec celery -A gramps_webapi.celery worker --loglevel=INFO --concurrency=2
5353
volumes:
5454
$$cap_appname-users:
5555
$$cap_appname-index:

examples/digitalocean-1click/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ services:
3636
VIRTUAL_HOST: ""
3737
LETSENCRYPT_HOST: ""
3838
LETSENCRYPT_EMAIL: ""
39-
command: celery -A gramps_webapi.celery worker --loglevel=INFO
39+
command: celery -A gramps_webapi.celery worker --loglevel=INFO --concurrency=2
4040

4141
grampsweb_redis:
4242
image: docker.io/library/redis:7.2.4-alpine

examples/docker-compose-base/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ services:
2727
container_name: grampsweb_celery
2828
depends_on:
2929
- grampsweb_redis
30-
command: celery -A gramps_webapi.celery worker --loglevel=INFO
30+
command: celery -A gramps_webapi.celery worker --loglevel=INFO --concurrency=2
3131

3232
grampsweb_redis:
3333
image: docker.io/library/redis:7.2.4-alpine

examples/docker-compose-letsencrypt/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ services:
3737
VIRTUAL_HOST: ""
3838
LETSENCRYPT_HOST: ""
3939
LETSENCRYPT_EMAIL: ""
40-
command: celery -A gramps_webapi.celery worker --loglevel=INFO
40+
command: celery -A gramps_webapi.celery worker --loglevel=INFO --concurrency=2
4141

4242
grampsweb_redis:
4343
image: docker.io/library/redis:7.2.4-alpine

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ nav:
1818
- Update: install_setup/update.md
1919
- Using PostgreSQL: install_setup/postgres.md
2020
- Hosting media on S3: install_setup/s3.md
21-
- Limit CPU usage: install_setup/cpu-limited.md
21+
- Limit CPU & memory usage: install_setup/cpu-limited.md
2222
- 2.0 upgrade guide: install_setup/v2.md
2323
- Administration:
2424
- Introduction: administration/admin.md

0 commit comments

Comments
 (0)