Skip to content

Commit 375c9a0

Browse files
authored
Merge pull request #721 from OpenHistoricalMap/staging
Production release: Adjust Tiler DB resources and Optimize imposm tag filtering
2 parents e179ef4 + 7069a0c commit 375c9a0

7 files changed

Lines changed: 219 additions & 36 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.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: 6 additions & 5 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
78
- ./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:
@@ -136,10 +137,10 @@ services:
136137
volumes:
137138
tiler_pgdata:
138139
driver: local
139-
name: tiler_db_10_03
140+
name: tiler_db_16_03
140141
tiler_imposm_data:
141142
driver: local
142-
name: tiler_imposm_10_03
143+
name: tiler_imposm_16_03
143144

144145
networks:
145146
ohm_network:

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

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,134 @@
44
"exclude": [
55
"created_by",
66
"source",
7-
"source:datetime"
7+
"source:*",
8+
"source_ref",
9+
"note",
10+
"note:*",
11+
"fixme",
12+
"fixme:*",
13+
"FIXME",
14+
"todo",
15+
"description",
16+
"description:*",
17+
"comment",
18+
"wikimedia_commons",
19+
"image",
20+
"image:*",
21+
"website",
22+
"url",
23+
"email",
24+
"phone",
25+
"fax",
26+
"contact:*",
27+
"opening_hours",
28+
"opening_hours:*",
29+
"addr:*",
30+
"is_in",
31+
"is_in:*",
32+
"attribution",
33+
"license",
34+
35+
"tiger:*",
36+
"gnis:*",
37+
"NHD:*",
38+
"nhd:*",
39+
"NHDPlus:*",
40+
"ref:*",
41+
"nysgissam:*",
42+
"nypl:*",
43+
"nygisid",
44+
"bkln:*",
45+
"base_bbl",
46+
"yh:*",
47+
"nl_ahcb:*",
48+
"ign:*",
49+
"istatcom:*",
50+
"hf:*",
51+
"gvr:*",
52+
"LINZ:*",
53+
"TMC:*",
54+
"NJDOT_*",
55+
"A45_*",
56+
"ANR",
57+
"FIPS",
58+
"EDGE_ID",
59+
"OBJECTID",
60+
"GlobalID",
61+
"GLOBALID",
62+
"HFCS",
63+
"zhb_code",
64+
65+
"import",
66+
"import:*",
67+
"import_uuid",
68+
"import_edge_id",
69+
"converted_by",
70+
"upload",
71+
"pre_download",
72+
"dataset",
73+
"odbl",
74+
"odbl:note",
75+
"history",
76+
77+
"roof:*",
78+
"building:levels",
79+
"building:part",
80+
"building:material",
81+
"building:colour",
82+
"generator:*",
83+
"tactile_paving",
84+
"crossing:markings",
85+
"crossing:island",
86+
"crossing:barrier",
87+
"traffic_sign",
88+
"traffic_sign:*",
89+
"traffic_signals",
90+
"traffic_signals:*",
91+
"button_operated",
92+
"sidewalk",
93+
"sidewalk:*",
94+
"parking",
95+
"parking:*",
96+
"lit",
97+
"smoothness",
98+
"direction",
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"
8135
]
9136
},
10137
"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[@]}" &
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Setup a dedicated 'imposm' PostgreSQL role with optimized session parameters.
3+
# This avoids affecting Tegola/other services that share the same postgres user.
4+
set -e
5+
source "$(dirname "$0")/utils.sh"
6+
7+
log_message "Setting up imposm database role with optimized parameters..."
8+
9+
psql "$PG_CONNECTION" <<EOSQL
10+
DO \$\$
11+
BEGIN
12+
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'imposm') THEN
13+
CREATE ROLE imposm LOGIN PASSWORD '${IMPOSM_DB_PASSWORD:-$POSTGRES_PASSWORD}';
14+
RAISE NOTICE 'Created imposm role';
15+
END IF;
16+
END
17+
\$\$;
18+
19+
-- Permissions
20+
GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO imposm;
21+
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO imposm;
22+
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO imposm;
23+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO imposm;
24+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO imposm;
25+
26+
-- Session-level parameters (only apply to imposm connections, not Tegola)
27+
ALTER ROLE imposm IN DATABASE $POSTGRES_DB SET work_mem = '${IMPOSM_WORK_MEM:-1GB}';
28+
ALTER ROLE imposm IN DATABASE $POSTGRES_DB SET maintenance_work_mem = '${IMPOSM_MAINTENANCE_WORK_MEM:-10GB}';
29+
ALTER ROLE imposm IN DATABASE $POSTGRES_DB SET temp_buffers = '${IMPOSM_TEMP_BUFFERS:-64MB}';
30+
EOSQL
31+
32+
log_message "Imposm role setup complete."

images/tiler-imposm/start.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cat <<EOF >"$WORKDIR/config.json"
3131
{
3232
"cachedir": "$CACHE_DIR",
3333
"diffdir": "$DIFF_DIR",
34-
"connection": "postgis://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB",
34+
"connection": "postgis://imposm:${IMPOSM_DB_PASSWORD:-$POSTGRES_PASSWORD}@$POSTGRES_HOST/$POSTGRES_DB",
3535
"mapping": "/osm/config/imposm3.json",
3636
"replication_url": "$REPLICATION_URL"
3737
}
@@ -317,6 +317,9 @@ done
317317

318318
log_message "PostgreSQL is ready! Proceeding with setup..."
319319

320+
# Setup dedicated imposm role with optimized session parameters
321+
./scripts/setup_imposm_role.sh
322+
320323
# Run date functions
321324
execute_sql_file /usr/local/datefunctions/datefunctions.sql
322325

0 commit comments

Comments
 (0)