Skip to content

Commit 1d3685f

Browse files
committed
control cache warmup with environment variable
This commit introduces a new environment variable, WARMUP_ON_STARTUP, to control whether the Nominatim caches are warmed up when the container starts. Previously, the cache warming process ran unconditionally on every startup. This could be time-consuming and unnecessary in environments where a quick start is prioritized over a pre-warmed cache.
1 parent 5924f00 commit 1d3685f

File tree

7 files changed

+56
-20
lines changed

7 files changed

+56
-20
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,30 @@ jobs:
232232
# Verify that the exit code is zero
233233
CONTAINER_EXIT_CODE=$(docker inspect nominatim --format='{{.State.ExitCode}}')
234234
test "$CONTAINER_EXIT_CODE" -eq 0
235+
236+
- name: WARMUP_ON_STARTUP=true
237+
commands: |-
238+
docker run -i --rm \
239+
-e PBF_URL=http://download.geofabrik.de/europe/monaco-latest.osm.pbf \
240+
-e WARMUP_ON_STARTUP=true \
241+
-p 8012:8080 \
242+
--name nominatim \
243+
nominatim &
244+
245+
./assert-non-empty-json "http://localhost:8012/search.php?q=avenue%20pasteur"
246+
docker logs nominatim | grep "Warming finished"
247+
248+
- name: WARMUP_ON_STARTUP=false
249+
commands: |-
250+
docker run -i --rm \
251+
-e PBF_URL=http://download.geofabrik.de/europe/monaco-latest.osm.pbf \
252+
-e WARMUP_ON_STARTUP=false \
253+
-p 8013:8080 \
254+
--name nominatim \
255+
nominatim &
256+
257+
./assert-non-empty-json "http://localhost:8013/search.php?q=avenue%20pasteur"
258+
docker logs nominatim | grep "Skipping cache warmup"
235259
236260
steps:
237261
- name: Download artifact

5.0/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ COPY --from=build / /
9696

9797
# Please override this
9898
ENV NOMINATIM_PASSWORD=qaIACxO6wMR3
99+
ENV WARMUP_ON_STARTUP=false
99100

100101
ENV PROJECT_DIR=/nominatim
101102

5.0/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Other places at Geofabrik follow the pattern `https://download.geofabrik.de/$CON
6363
- `IMPORT_TIGER_ADDRESSES`: Whether to download and import the Tiger address data (`true`) or path to a preprocessed Tiger address set in the container. (default: `false`)
6464
- `THREADS`: How many threads should be used to import (default: number of processing units available to the current process via `nproc`)
6565
- `NOMINATIM_PASSWORD`: The password to connect to the database with (default: `qaIACxO6wMR3`)
66+
- `WARMUP_ON_STARTUP`: Whether to warm up the database caches on container startup by loading tables and indices into RAM. This can improve initial query performance, especially on systems with slow disks and sufficient RAM. However, it will increase the container's startup time. Set to `true` to enable. (default: `false`)
6667

6768
The following run parameters are available for configuration:
6869

5.0/start.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,22 @@ fi
6767
tail -Fv /var/log/postgresql/postgresql-16-main.log &
6868
tailpid=${!}
6969

70-
export NOMINATIM_QUERY_TIMEOUT=600
71-
export NOMINATIM_REQUEST_TIMEOUT=3600
72-
if [ "$REVERSE_ONLY" = "true" ]; then
73-
echo "Warm database caches for reverse queries"
74-
sudo -H -E -u nominatim nominatim admin --warm --reverse > /dev/null
70+
if [ "$WARMUP_ON_STARTUP" = "true" ]; then
71+
export NOMINATIM_QUERY_TIMEOUT=600
72+
export NOMINATIM_REQUEST_TIMEOUT=3600
73+
if [ "$REVERSE_ONLY" = "true" ]; then
74+
echo "Warm database caches for reverse queries"
75+
sudo -H -E -u nominatim nominatim admin --warm --reverse > /dev/null
76+
else
77+
echo "Warm database caches for search and reverse queries"
78+
sudo -H -E -u nominatim nominatim admin --warm > /dev/null
79+
fi
80+
export NOMINATIM_QUERY_TIMEOUT=10
81+
export NOMINATIM_REQUEST_TIMEOUT=60
82+
echo "Warming finished"
7583
else
76-
echo "Warm database caches for search and reverse queries"
77-
sudo -H -E -u nominatim nominatim admin --warm > /dev/null
84+
echo "Skipping cache warmup"
7885
fi
79-
export NOMINATIM_QUERY_TIMEOUT=10
80-
export NOMINATIM_REQUEST_TIMEOUT=60
81-
echo "Warming finished"
8286

8387
echo "--> Nominatim is ready to accept requests"
8488

5.1/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ COPY --from=build / /
9090

9191
# Please override this
9292
ENV NOMINATIM_PASSWORD=qaIACxO6wMR3
93+
ENV WARMUP_ON_STARTUP=false
9394

9495
ENV PROJECT_DIR=/nominatim
9596

5.1/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Other places at Geofabrik follow the pattern `https://download.geofabrik.de/$CON
6464
- `THREADS`: How many threads should be used to import (default: number of processing units available to the current process via `nproc`)
6565
- `GUNICORN_WORKERS`: Specifies how many Gunicorn worker processes should handle API requests. If not explicitly set, it defaults to the number of available CPU cores `(nproc)`. Increase this value to improve concurrent request handling capacity, but ensure it aligns with your server's CPU resources.
6666
- `NOMINATIM_PASSWORD`: The password to connect to the database with (default: `qaIACxO6wMR3`)
67+
- `WARMUP_ON_STARTUP`: Whether to warm up the database caches on container startup by loading tables and indices into RAM. This can improve initial query performance, especially on systems with slow disks and sufficient RAM. However, it will increase the container's startup time. Set to `true` to enable. (default: `false`)
6768

6869
The following run parameters are available for configuration:
6970

5.1/start.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,22 @@ fi
6767
tail -Fv /var/log/postgresql/postgresql-16-main.log &
6868
tailpid=${!}
6969

70-
export NOMINATIM_QUERY_TIMEOUT=600
71-
export NOMINATIM_REQUEST_TIMEOUT=3600
72-
if [ "$REVERSE_ONLY" = "true" ]; then
73-
echo "Warm database caches for reverse queries"
74-
sudo -H -E -u nominatim nominatim admin --warm --reverse > /dev/null
70+
if [ "$WARMUP_ON_STARTUP" = "true" ]; then
71+
export NOMINATIM_QUERY_TIMEOUT=600
72+
export NOMINATIM_REQUEST_TIMEOUT=3600
73+
if [ "$REVERSE_ONLY" = "true" ]; then
74+
echo "Warm database caches for reverse queries"
75+
sudo -H -E -u nominatim nominatim admin --warm --reverse > /dev/null
76+
else
77+
echo "Warm database caches for search and reverse queries"
78+
sudo -H -E -u nominatim nominatim admin --warm > /dev/null
79+
fi
80+
export NOMINATIM_QUERY_TIMEOUT=10
81+
export NOMINATIM_REQUEST_TIMEOUT=60
82+
echo "Warming finished"
7583
else
76-
echo "Warm database caches for search and reverse queries"
77-
sudo -H -E -u nominatim nominatim admin --warm > /dev/null
84+
echo "Skipping cache warmup"
7885
fi
79-
export NOMINATIM_QUERY_TIMEOUT=10
80-
export NOMINATIM_REQUEST_TIMEOUT=60
81-
echo "Warming finished"
8286

8387
# Set default number of workers if not specified
8488
if [ -z "$GUNICORN_WORKERS" ]; then

0 commit comments

Comments
 (0)