Skip to content

Commit 4a7c76a

Browse files
authored
Merge pull request #494 from OpenHistoricalMap/staging
Optimizing Vector Tiles: Merging Duplicated Boundary Lines
2 parents 4188c64 + bc073eb commit 4a7c76a

19 files changed

+768
-446
lines changed

.github/workflows/chartpress.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- 'main'
66
- 'staging'
77
- 'development'
8-
- 'refactor/web_docker'
8+
- 'admin_lines'
99
jobs:
1010
build:
1111
runs-on: ubuntu-20.04

.github/workflows/frontend-nominatim.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches:
66
- 'main'
77
- 'staging'
8-
- 'nominatim-ui'
98

109
jobs:
1110
nominatim:
@@ -17,10 +16,10 @@ jobs:
1716
with:
1817
access_token: ${{ github.token }}
1918

20-
- name: Set environment variables - Staging
19+
- name: Set environment variables - Staging & Nominatim-UI-2
2120
if: github.ref == 'refs/heads/staging'
2221
run: |
23-
echo "NOMINATIM_API=https://nominatim-api.staging.openhistoricalmap.org/" >> $GITHUB_ENV
22+
echo "NOMINATIM_API=https://nominatim-api.openhistoricalmap.org/" >> $GITHUB_ENV
2423
echo "NOMINATIM_BUCKET=nominatim-staging.openhistoricalmap.org" >> $GITHUB_ENV
2524
echo "CLOUDFRONT_DISTRIBUTION_ID=${{ secrets.STAGING_NOMINATIM_CLOUDFRONT_ID }}" >> $GITHUB_ENV
2625
@@ -38,10 +37,15 @@ jobs:
3837
ref: c14d033389acedf4dcbaabd9d88e14bc40212279
3938
fetch-depth: 0
4039

40+
- name: Install Dependencies with Legacy Peer Deps
41+
run: |
42+
npm install --legacy-peer-deps
43+
npm install rollup-plugin-svelte@latest --save-dev --legacy-peer-deps
44+
4145
- name: Build nominatim-ui frontend
4246
run: |
4347
echo "Nominatim_Config.Nominatim_API_Endpoint = '${NOMINATIM_API}';" >> dist/theme/config.theme.js
44-
# npm run build
48+
npm run build
4549
4650
- name: Set up Python
4751
uses: actions/setup-python@v4
@@ -55,7 +59,7 @@ jobs:
5559
5660
- name: Deploy to S3 and Invalidate CloudFront
5761
run: |
58-
aws s3 sync dist/ s3://${NOMINATIM_BUCKET}/ --delete
62+
aws s3 sync dist/ s3://${NOMINATIM_BUCKET}/
5963
aws cloudfront create-invalidation --distribution-id=${CLOUDFRONT_DISTRIBUTION_ID} --paths "/*"
6064
env:
6165
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}

.github/workflows/frontend-overpass.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
uses: actions/checkout@v4
4545
with:
4646
repository: OpenHistoricalMap/overpass-turbo
47-
ref: ac9201e6b9a28cf6883335d4a956b3120509c972
47+
ref: 1a57c9348fb9b23a9ecb1109b54f3fc311331213
4848
path: overpass-turbo
4949

5050
- name: Enable Corepack

hetzner/config/postgresql.production.conf

+44-44
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
#------------------------------------------------------------------------------
22
# CONNECTIONS AND AUTHENTICATION
33
#------------------------------------------------------------------------------
4-
5-
listen_addresses = '*' # Allow connections from all addresses
6-
max_connections = 200 # Increase connections for a larger server
7-
superuser_reserved_connections = 5 # Reserve for superusers
4+
listen_addresses = '*' # Allow connections from any network interface
5+
max_connections = 200 # Increase if you expect more concurrent connections
6+
superuser_reserved_connections = 5 # Reserve connections for superusers
87

98
#------------------------------------------------------------------------------
109
# RESOURCE USAGE
1110
#------------------------------------------------------------------------------
1211

1312
# - Memory Configuration -
14-
shared_buffers = 14GB # Allocate ~25% of total memory
15-
work_mem = 512MB # Increase per-query memory
16-
maintenance_work_mem = 4GB # Allow more memory for VACUUM/ALTER operations
17-
effective_cache_size = 41GB # 75% of total memory for caching
13+
shared_buffers = 14GB # ~25% of total 55GB; adjust if needed
14+
work_mem = 256MB # Memory for each sort/hash operation; be cautious with many parallel queries
15+
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
1817

19-
# - Disk Optimization for SSD -
20-
random_page_cost = 1.0 # Optimize for SSD storage
21-
seq_page_cost = 1.0 # Default for sequential scans
18+
# - Disk Optimization for SSD (if using SSD) -
19+
random_page_cost = 1.0 # Lower cost for random I/O on SSD
20+
seq_page_cost = 1.0 # Default cost for sequential scans
2221

2322
#------------------------------------------------------------------------------
2423
# WRITE-AHEAD LOG (WAL)
2524
#------------------------------------------------------------------------------
26-
27-
wal_level = replica # Required for replication if needed
28-
checkpoint_timeout = 15min # Increase checkpoint frequency
29-
max_wal_size = 4GB # Allow more WAL before forcing a checkpoint
30-
min_wal_size = 1GB # Set a lower boundary for WAL size
31-
wal_compression = lz4 # Enable LZ4 compression for WAL files (default in PG 17)
32-
synchronous_commit = off # Improve performance by reducing commit overhead
25+
wal_level = replica # Required for replication; 'minimal' if no replication is used
26+
checkpoint_timeout = 15min # Interval between automatic WAL checkpoints
27+
max_wal_size = 4GB # Amount of WAL to accumulate before forcing a checkpoint
28+
min_wal_size = 1GB # Minimum size to keep WAL files
29+
wal_compression = lz4 # Compress WAL segments to reduce disk usage (PG17 default)
30+
synchronous_commit = off # Improves write performance, risk of data loss if crash
3331

3432
#------------------------------------------------------------------------------
3533
# AUTOVACUUM SETTINGS
3634
#------------------------------------------------------------------------------
37-
38-
autovacuum_max_workers = 6 # More workers due to higher CPU count
39-
autovacuum_naptime = 30s # Run autovacuum frequently
40-
autovacuum_vacuum_cost_limit = -1 # Allow PostgreSQL to auto-adjust vacuum cost
35+
autovacuum_max_workers = 6 # More parallel vacuum workers for busy systems
36+
autovacuum_naptime = 30s # How often the autovacuum daemon checks for work
37+
autovacuum_vacuum_cost_limit = -1 # Let PostgreSQL adjust vacuum cost dynamically
4138

4239
#------------------------------------------------------------------------------
4340
# QUERY TUNING
4441
#------------------------------------------------------------------------------
45-
46-
effective_io_concurrency = 300 # Optimize IO operations for SSDs
47-
parallel_tuple_cost = 0.1 # Encourage parallel execution
48-
parallel_setup_cost = 500 # Lower parallel setup cost
49-
max_worker_processes = 28 # Utilize all CPU cores
50-
max_parallel_workers_per_gather = 8 # Allow more parallel workers per query
51-
max_parallel_workers = 28 # Utilize all available parallel workers
42+
effective_io_concurrency = 300 # For SSD; helps the planner estimate IO concurrency
43+
parallel_tuple_cost = 0.1 # Lower cost to encourage parallelization
44+
parallel_setup_cost = 500 # 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
5248

5349
#------------------------------------------------------------------------------
5450
# LOGGING
5551
#------------------------------------------------------------------------------
56-
57-
logging_collector = off # Disable logging to improve performance
58-
log_statement = 'none' # Disable all SQL statement logging
59-
log_min_duration_statement = -1 # Do not log slow queries
60-
log_duration = off # Disable duration logging
61-
log_error_verbosity = terse # Show minimal error messages
62-
63-
; #------------------------------------------------------------------------------
64-
; # CLIENT CONNECTION DEFAULTS
65-
; #------------------------------------------------------------------------------
66-
67-
; statement_timeout = 600000 # Terminate queries running longer than 10 min
68-
; lock_timeout = 600000 # Timeout for acquiring locks
69-
; idle_in_transaction_session_timeout = 600000 # Close idle transactions after 10 min
52+
logging_collector = off # Disable log collection
53+
log_statement = 'none' # Do not log any statements
54+
log_duration = off # Disable logging query duration
55+
log_min_duration_statement = -1 # Disable logging slow queries
56+
log_error_verbosity = terse # Minimal error messages
57+
log_autovacuum_min_duration = -1 # Do not log autovacuum runs
58+
log_connections = on # Do not log new connections
59+
log_disconnections = on # Do not log disconnections
60+
log_lock_waits = off # Do not log lock waits
61+
log_temp_files = -1 # Do not log temporary file creation
62+
log_checkpoints = off # Do not log checkpoints
63+
log_replication_commands = off # Do not log replication-related commands
64+
log_directory = '/dev/null' # Redirect logs to /dev/null (no storage)
65+
#------------------------------------------------------------------------------
66+
# CLIENT CONNECTION DEFAULTS
67+
#------------------------------------------------------------------------------
68+
statement_timeout = 600000 # Kill any query running longer than 10 minutes
69+
lock_timeout = 600000 # Timeout for acquiring locks
70+
idle_in_transaction_session_timeout = 600000 # Close transactions idle for more than 10 minutes
7071

7172
#------------------------------------------------------------------------------
7273
# LOCALE AND TIMING
7374
#------------------------------------------------------------------------------
74-
7575
datestyle = 'iso, mdy'
7676
timezone = 'Etc/UTC'
7777
lc_messages = 'en_US.utf8'

hetzner/seed.sh

+16-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ seed_global() {
1111
--map=osm \
1212
--min-zoom=0 \
1313
--max-zoom=5 \
14-
--concurrency=32 \
14+
--concurrency=4 \
1515
--overwrite=true
1616

1717
# Seed land areas separately (zoom 6-7)
@@ -24,11 +24,11 @@ seed_global() {
2424
--map=osm \
2525
--min-zoom="$zoom" \
2626
--max-zoom="$zoom" \
27-
--concurrency=32 \
27+
--concurrency=4 \
2828
--overwrite=true
2929
done
30-
echo "Global seeding completed. Sleeping for 1 hour..."
31-
sleep 3600
30+
echo "Global seeding completed. Sleeping for 3 hour..."
31+
sleep 10800
3232
done
3333
}
3434

@@ -38,13 +38,18 @@ seed_coverage() {
3838
wget -O /opt/tile-list.tiles "https://s3.amazonaws.com/planet.openhistoricalmap.org/tile_coverage/tiles_14.list"
3939
pkill -f "tegola" && sleep 5
4040

41-
tegola cache seed tile-list /opt/tile-list.tiles \
42-
--config=/opt/tegola_config/config.toml \
43-
--map=osm \
44-
--min-zoom=0 \
45-
--max-zoom=14 \
46-
--concurrency=32 \
47-
--overwrite=false
41+
for zoom in $(seq 8 14); do
42+
echo "Downloading tile list for zoom level $zoom..."
43+
wget -O /opt/tile-list.tiles "https://s3.amazonaws.com/planet.openhistoricalmap.org/tile_coverage/tiles_boundary_$zoom.list"
44+
45+
tegola cache seed tile-list /opt/tile-list.tiles \
46+
--config=/opt/tegola_config/config.toml \
47+
--map=osm \
48+
--min-zoom=$zoom \
49+
--max-zoom=$zoom \
50+
--concurrency=4 \
51+
--overwrite=false
52+
done
4853
sleep 300
4954
done
5055
}

hetzner/tiler.production.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424

2525
# imposm3
2626
imposm_production:
27-
image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.2191.hdcb5877
27+
image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.2296.h6936774
2828
volumes:
2929
- /data/tiler_production_imposm_20250211:/mnt/data
3030
command:
@@ -48,14 +48,14 @@ services:
4848
- tiler_network
4949
# Tiler server
5050
tiler_production:
51-
image: ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.2248.he042bfb
52-
ports:
53-
- "9090:9090"
54-
env_file:
55-
- .env.production
56-
restart: always
57-
networks:
58-
- tiler_network
51+
image: ghcr.io/openhistoricalmap/tiler-cache:0.0.1-0.dev.git.2238.h67c76c8
52+
ports:
53+
- "9090:9090"
54+
env_file:
55+
- .env.production
56+
restart: always
57+
networks:
58+
- tiler_network
5959
# Tiler cache
6060
cache_production:
6161
image: ghcr.io/openhistoricalmap/tiler-cache:0.0.1-0.dev.git.2238.h67c76c8

hetzner/tiler.staging.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424
memory: 2G
2525

2626
imposm:
27-
image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.2191.hdcb5877
27+
image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.2296.h6936774
2828
volumes:
2929
- /data/tiler_production_imposm_20250225_v7:/mnt/data
3030
command:
@@ -43,7 +43,7 @@ services:
4343
cpus: '1'
4444
memory: 1G
4545
tiler:
46-
image: ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.2248.he042bfb
46+
image: ghcr.io/openhistoricalmap/tiler-cache:0.0.1-0.dev.git.2238.h67c76c8
4747
ports:
4848
- "9091:9090"
4949
env_file:
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
--This is fuction to convert decimal date to iso date, in that it handles BCE dates properly, and it also returns NULL if any conversion error happens.
2+
--It is used in images/tiler-imposm/queries/mviews_admin_boundaries_merged.sql
3+
--This script differs from https://github.com/OpenHistoricalMap/DateFunctions-plpgsql/blob/master/datefunctions.sql
4+
CREATE OR REPLACE FUNCTION convert_decimal_to_iso_date(decimal_date NUMERIC)
5+
RETURNS VARCHAR AS $$
6+
DECLARE
7+
year_part INT;
8+
decimal_part NUMERIC;
9+
days_in_year INT;
10+
day_of_year INT;
11+
final_date DATE;
12+
formatted_year VARCHAR;
13+
BEGIN
14+
IF decimal_date IS NULL THEN
15+
RETURN NULL;
16+
END IF;
17+
18+
year_part := FLOOR(decimal_date);
19+
decimal_part := decimal_date - year_part;
20+
21+
-- Determine number of days in the year (leap year check)
22+
days_in_year := CASE
23+
WHEN (year_part % 4 = 0 AND year_part % 100 <> 0) OR (year_part % 400 = 0)
24+
THEN 366 -- Leap year
25+
ELSE 365 -- Regular year
26+
END;
27+
28+
-- Convert decimal fraction to day of the year
29+
day_of_year := CEIL(decimal_part * days_in_year);
30+
31+
-- Format the year properly for BCE cases
32+
IF year_part < 1 THEN
33+
formatted_year := LPAD(ABS(year_part - 1)::TEXT, 4, '0'); -- Convert BCE format
34+
formatted_year := '-' || formatted_year; -- Add negative sign for BCE
35+
ELSE
36+
formatted_year := LPAD(year_part::TEXT, 4, '0');
37+
END IF;
38+
39+
-- Try converting year + day-of-year into full ISO date
40+
BEGIN
41+
final_date := TO_DATE(formatted_year || '-' || day_of_year, 'YYYY-DDD');
42+
EXCEPTION
43+
WHEN others THEN
44+
RETURN NULL; -- If any conversion error happens, return NULL
45+
END;
46+
47+
RETURN TO_CHAR(final_date, 'YYYY-MM-DD');
48+
END;
49+
$$
50+
LANGUAGE plpgsql;
51+
52+
53+
-- This function converts a date in ISO format to a decimal date. usually user in triggers
54+
CREATE OR REPLACE FUNCTION convert_dates_to_decimal ()
55+
RETURNS TRIGGER AS
56+
$$
57+
BEGIN
58+
NEW.start_decdate := isodatetodecimaldate(pad_date(NEW.start_date::TEXT, 'start')::TEXT, FALSE);
59+
NEW.end_decdate := isodatetodecimaldate(pad_date(NEW.end_date::TEXT, 'end')::TEXT, FALSE);
60+
RETURN NEW;
61+
END;
62+
$$
63+
LANGUAGE plpgsql;

images/tiler-imposm/queries/mviews_admin_boundaries.sql

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ BEGIN
5252
FROM %s;
5353
$sql$, zoom, table_name);
5454

55+
-- NOTE: Do not create admin lines since we are merging in mviews_admin_boundaries_merged.sql
5556
EXECUTE sql_create_lines;
5657
RAISE NOTICE 'Created materialized view: mview_admin_boundaries_lines_%s', zoom;
5758

0 commit comments

Comments
 (0)