Skip to content

Commit 7069a0c

Browse files
committed
Optimize imposm tag filtering and adjust tiler_db resoruces
1 parent 4922b4f commit 7069a0c

8 files changed

Lines changed: 128 additions & 153 deletions

File tree

.github/workflows/chartpress.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- 'main'
66
- 'staging'
7-
- 'vtiles_admin_attr'
7+
- 'tags_imposm'
88
jobs:
99
build:
1010
runs-on: ubuntu-22.04
@@ -71,7 +71,7 @@ jobs:
7171
OHM_SLACK_WEBHOOK_URL: ${{ secrets.OHM_SLACK_WEBHOOK_URL }}
7272
################ Staging secrets ################
7373
- name: Staging - substitute secrets
74-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/vtiles_admin_attr'
74+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/tags_imposm'
7575
uses: bluwy/substitute-string-action@v1
7676
with:
7777
_input-file: 'values.staging.template.yaml'
@@ -189,14 +189,14 @@ jobs:
189189
PRODUCTION_OPENSTREETMAP_AUTH_SECRET: ${{ secrets.PRODUCTION_OPENSTREETMAP_AUTH_SECRET }}
190190

191191
- name: AWS Credentials
192-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/vtiles_admin_attr'
192+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/tags_imposm'
193193
uses: aws-actions/configure-aws-credentials@v1
194194
with:
195195
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
196196
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
197197
aws-region: us-east-1
198198
- name: Setup Kubectl and Helm Dependencies
199-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/vtiles_admin_attr'
199+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/tags_imposm'
200200
run: |
201201
sudo pip install awscli --ignore-installed six
202202
sudo curl -L -o /usr/bin/kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.17.7/2020-07-08/bin/linux/amd64/kubectl
@@ -210,22 +210,22 @@ jobs:
210210
helm version
211211
212212
- name: Update kube-config staging
213-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/vtiles_admin_attr'
213+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/tags_imposm'
214214
run: aws eks --region us-east-1 update-kubeconfig --name osmseed-staging
215215
- name: Update kube-config prod
216216
if: github.ref == 'refs/heads/main'
217217
run: aws eks --region us-east-1 update-kubeconfig --name osmseed-production-v2
218218
- name: Add Helm repository
219-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/vtiles_admin_attr'
219+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/tags_imposm'
220220
run: |
221221
helm repo add osm-seed https://osm-seed.github.io/osm-seed-chart/
222222
helm repo update
223223
- name: Install helm dependencies for
224-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/vtiles_admin_attr'
224+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/tags_imposm'
225225
run: cd ohm && helm dep up
226226
# Staging
227227
- name: Staging - helm deploy
228-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/vtiles_admin_attr'
228+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/tags_imposm'
229229
run: helm upgrade --install staging --wait ohm/ -f values.staging.yaml -f ohm/values.yaml
230230
# Production
231231
- name: Production - helm deploy

hetzner/tiler/config/postgresql.imposm.conf

Lines changed: 0 additions & 95 deletions
This file was deleted.

hetzner/tiler/config/postgresql.production.conf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ superuser_reserved_connections = 5 # Reserve connections for superusers
1010
#------------------------------------------------------------------------------
1111

1212
# - Memory Configuration -
13-
shared_buffers = 14GB # ~25% of total 55GB; adjust if needed
13+
shared_buffers = 10GB # ~25% of 40GB container limit
1414
work_mem = 256MB # Memory for each sort/hash operation; be cautious with many parallel queries
1515
maintenance_work_mem = 4GB # Larger memory for VACUUM / CREATE INDEX / ALTER
16-
effective_cache_size = 36GB # ~60-70% of total memory to inform the planner
16+
effective_cache_size = 26GB # ~65% of 40GB container limit
1717

1818
# - Disk Optimization for SSD (if using SSD) -
1919
random_page_cost = 1.0 # Lower cost for random I/O on SSD
@@ -42,9 +42,9 @@ autovacuum_vacuum_cost_limit = -1 # Let PostgreSQL adjust vacuum cost d
4242
effective_io_concurrency = 300 # For SSD; helps the planner estimate IO concurrency
4343
parallel_tuple_cost = 0.001 # Lower cost to encourage parallelization
4444
parallel_setup_cost = 100 # Lower to encourage more parallel plans
45-
max_worker_processes = 28 # Allow up to 28 worker processes
46-
max_parallel_workers_per_gather = 8 # Max workers that can help a single query
47-
max_parallel_workers = 28 # Total number of parallel workers across all queries
45+
max_worker_processes = 25 # Match 25 CPUs container limit
46+
max_parallel_workers_per_gather = 6 # Max workers that can help a single query
47+
max_parallel_workers = 25 # Total number of parallel workers across all queries
4848

4949
#------------------------------------------------------------------------------
5050
# LOGGING

hetzner/tiler/tiler.production.yml

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ services:
22
tiler_db:
33
container_name: tiler_db
44
image: ghcr.io/openhistoricalmap/tiler-db:0.0.1-0.dev.git.2166.hc55c4cd
5+
command: postgres -c config_file=/etc/postgresql/postgresql.conf
56
volumes: !overwrite
67
- tiler_pgdata:/var/lib/postgresql/data
7-
- ./config/${PG_CONFIG:-postgresql.production.conf}:/etc/postgresql/postgresql.conf
8+
- ./config/postgresql.production.conf:/etc/postgresql/postgresql.conf
89
ports:
910
- "54329:5432"
1011
env_file:
1112
- .env.tiler
12-
mem_limit: 55G
13-
cpus: "28.0"
13+
mem_limit: 40G
14+
cpus: "25.0"
1415
networks:
1516
- ohm_network
1617

1718
tiler_imposm:
1819
container_name: tiler_imposm
19-
image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.3325.hb9f97989
20+
image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.3323.haf36ae7d
2021
volumes:
2122
- tiler_imposm_data:/mnt/data
2223
env_file:
@@ -132,35 +133,14 @@ services:
132133
- .env.tiler
133134
networks:
134135
- ohm_network
135-
136-
tiler_pipeline_monitor:
137-
container_name: tiler_pipeline_monitor
138-
image: ghcr.io/openhistoricalmap/tiler-pipeline-monitor:0.0.1
139-
ports:
140-
- "8001:8001"
141-
environment:
142-
- CHECK_INTERVAL=300
143-
- REPLICATION_LAG_THRESHOLD=600
144-
- MV_REFRESH_THRESHOLD=600
145-
- IMPOSM_IMPORT_MAX_AGE=900
146-
env_file:
147-
- .env.tiler
148-
restart: always
149-
healthcheck:
150-
test: ["CMD", "curl", "-f", "http://localhost:8001/health"]
151-
interval: 30s
152-
retries: 3
153-
timeout: 10s
154-
networks:
155-
- ohm_network
156136

157137
volumes:
158138
tiler_pgdata:
159139
driver: local
160-
name: tiler_db_10_03
140+
name: tiler_db_16_03
161141
tiler_imposm_data:
162142
driver: local
163-
name: tiler_imposm_10_03
143+
name: tiler_imposm_16_03
164144

165145
networks:
166146
ohm_network:

images/tiler-imposm/config/imposm3.template.json

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,42 @@
9696
"lit",
9797
"smoothness",
9898
"direction",
99-
"ele"
99+
"ele",
100+
101+
"building",
102+
"natural",
103+
"landuse",
104+
"highway",
105+
"railway",
106+
"aeroway",
107+
"waterway",
108+
"barrier",
109+
"leisure",
110+
"historic",
111+
"man_made",
112+
"power",
113+
"military",
114+
"amenity",
115+
"place",
116+
"tourism",
117+
"shop",
118+
"craft",
119+
"boundary",
120+
"communication",
121+
"route",
122+
"start_date",
123+
"end_date",
124+
"name",
125+
"oneway",
126+
"bridge",
127+
"access",
128+
"service",
129+
"ford",
130+
"surface",
131+
"lanes",
132+
"maxspeed",
133+
"admin_level",
134+
"type"
100135
]
101136
},
102137
"generalized_tables": {},

images/tiler-imposm/scripts/refresh_mviews.sh

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,37 @@ source ./scripts/utils.sh
2828
# Example:
2929
# refresh_mviews_group "WATER" 180 "${water_views[@]}" &
3030
# ============================================================================
31+
LIGHT_WORK_MEM="64MB"
32+
LIGHT_MAINT_MEM="256MB"
33+
HEAVY_WORK_MEM="512MB"
34+
HEAVY_MAINT_MEM="4GB"
35+
3136
function refresh_mviews_group() {
3237
local group_name="$1"
3338
local sleep_interval="$2"
34-
shift 2
39+
local mem_profile="${3:-light}" # "light" or "heavy"
40+
shift 3
3541
local materialized_views=("$@")
3642

43+
local work_mem="$LIGHT_WORK_MEM"
44+
local maint_mem="$LIGHT_MAINT_MEM"
45+
if [ "$mem_profile" = "heavy" ]; then
46+
work_mem="$HEAVY_WORK_MEM"
47+
maint_mem="$HEAVY_MAINT_MEM"
48+
fi
49+
3750
while true; do
3851
for mview in "${materialized_views[@]}"; do
39-
log_message "[$group_name] Refreshing $mview..."
52+
log_message "[$group_name] Refreshing $mview (work_mem=$work_mem, maintenance_work_mem=$maint_mem)..."
4053
local error_output
4154
# Disable statement_timeout for long-running refresh operations (0 = no limit)
4255
local exit_code=0
4356
local start_time=$SECONDS
44-
error_output=$(psql "$PG_CONNECTION" -v ON_ERROR_STOP=1 -c "SET statement_timeout = 0" -c "REFRESH MATERIALIZED VIEW CONCURRENTLY $mview;" 2>&1) || exit_code=$?
57+
error_output=$(psql "$PG_CONNECTION" -v ON_ERROR_STOP=1 \
58+
-c "SET statement_timeout = 0" \
59+
-c "SET work_mem = '$work_mem'" \
60+
-c "SET maintenance_work_mem = '$maint_mem'" \
61+
-c "REFRESH MATERIALIZED VIEW CONCURRENTLY $mview;" 2>&1) || exit_code=$?
4562
local elapsed=$((SECONDS - start_time))
4663
if [ $exit_code -eq 0 ]; then
4764
log_message "[$group_name] ✅ Successfully refreshed $mview. Time: ${elapsed}s"
@@ -249,18 +266,21 @@ no_admin_boundaries_views=(
249266
)
250267

251268

252-
refresh_mviews_group "ADMIN_BOUNDARIES_LINES" 60 "${admin_boundaries_lines_views[@]}" &
253-
refresh_mviews_group "ADMIN_BOUNDARIES_AREAS_CENTROIDS" 180 "${admin_boundaries_areas_centroids_views[@]}" &
254-
refresh_mviews_group "ADMIN_MARITIME_LINES" 300 "${admin_maritime_lines_views[@]}" &
255-
refresh_mviews_group "TRANSPORTS" 180 "${transport_views[@]}" &
256-
refresh_mviews_group "AMENITY" 180 "${amenity_views[@]}" &
257-
refresh_mviews_group "LANDUSE" 180 "${landuse_views[@]}" &
258-
refresh_mviews_group "OTHERS" 180 "${others_views[@]}" &
259-
refresh_mviews_group "COMMUNICATION" 180 "${communication_views[@]}" &
260-
refresh_mviews_group "PLACES" 180 "${places_views[@]}" &
261-
refresh_mviews_group "WATER" 180 "${water_views[@]}" &
262-
refresh_mviews_group "BUILDINGS" 180 "${buildings_views[@]}" &
263-
refresh_mviews_group "ROUTES" 180 "${routes_views[@]}" &
269+
# Heavy groups - admin boundaries have the largest tables
270+
refresh_mviews_group "ADMIN_BOUNDARIES_LINES" 60 heavy "${admin_boundaries_lines_views[@]}" &
271+
refresh_mviews_group "ADMIN_BOUNDARIES_AREAS_CENTROIDS" 180 heavy "${admin_boundaries_areas_centroids_views[@]}" &
272+
273+
# Light groups - smaller tables, minimal resources
274+
refresh_mviews_group "ADMIN_MARITIME_LINES" 300 light "${admin_maritime_lines_views[@]}" &
275+
refresh_mviews_group "TRANSPORTS" 180 heavy "${transport_views[@]}" &
276+
refresh_mviews_group "AMENITY" 180 light "${amenity_views[@]}" &
277+
refresh_mviews_group "LANDUSE" 180 light "${landuse_views[@]}" &
278+
refresh_mviews_group "OTHERS" 180 light "${others_views[@]}" &
279+
refresh_mviews_group "COMMUNICATION" 180 light "${communication_views[@]}" &
280+
refresh_mviews_group "PLACES" 180 light "${places_views[@]}" &
281+
refresh_mviews_group "WATER" 180 light "${water_views[@]}" &
282+
refresh_mviews_group "BUILDINGS" 180 light "${buildings_views[@]}" &
283+
refresh_mviews_group "ROUTES" 180 light "${routes_views[@]}" &
264284

265285
## This group high demand, so we refresh every 1 hour
266-
refresh_mviews_group "NO_ADMIN_BOUNDARIES" 36000 "${no_admin_boundaries_views[@]}" &
286+
refresh_mviews_group "NO_ADMIN_BOUNDARIES" 36000 light "${no_admin_boundaries_views[@]}" &

0 commit comments

Comments
 (0)