Repository navigation
Description
From: #909
To improve the performance of SELECT queries in the database, I have decided to eliminate the use of functions such as ST_Simplify, JSONB, and Filters , etc.
These functionalities, such as geometry simplification, JSON selection, and filtering, will be moved to Imposm. It will handle geometry simplification and apply filters during insertion and updates. This way, the PostgreSQL functions and filters will only run once, reducing the load during SELECT queries .
How will this process work in Imposm?
For example, in the water_lines layer, in the previous workflow with Imposm, we only had 3 tables:
- water_lines_gen0
- water_lines_gen1
- water_lines.
Now, for water_lines, we have tables structured according to the zoom levels:
- water_lines_zoom_8_9
- water_lines_zoom_10_11
- water_lines_zoom_12_14
- water_lines_zoom_15_20
- water_lines
To achieve this, it will use the generalized_tables functionality in the Imposm configuration. This feature allows us to create simplified (or “generalized”) versions of geometries with different levels of detail and specific filters.
Previous Structure:
The previous structure consisted of a limited set of tables.
{
"tags": {
"load_all": true,
"exclude": ["created_by", "source", "source:datetime"]
},
"generalized_tables": {
"water_lines_gen0": {
"source": "water_lines_gen1",
"sql_filter": null,
"tolerance": 200
},
"water_lines_gen1": {
"source": "water_lines",
"sql_filter": null,
"tolerance": 50.0
}
},
"tables": {
"water_lines": {
"fields": [
{
"type": "id",
"name": "osm_id",
"key": null
},
....
}
}New Structure:
In the new structure, I create additional tables with appropriate filters tailored for specific zoom levels.
{
"tags": {
"load_all": true,
"exclude": [
"created_by",
"source",
"source:datetime"
]
},
"generalized_tables": {
"water_lines_zoom_8_9": {
"source": "water_lines",
"sql_filter": "type IN ('river', 'canal')",
"tolerance": 1000
},
"water_lines_zoom_10_11": {
"source": "water_lines",
"sql_filter": "type IN ('river', 'canal', 'cliff', 'dam')",
"tolerance": 100
},
"water_lines_zoom_12_14": {
"source": "water_lines",
"sql_filter": "type IN ('river', 'canal', 'cliff', 'dam', 'stream')",
"tolerance": 10
},
"water_lines_zoom_15_20": {
"source": "water_lines",
"sql_filter": "type IN ('river', 'canal', 'cliff', 'dam', 'stream', 'ditch', 'drain')"
}
},
"tables": {
"water_lines": {
"fields": [
{
"type": "id",
"name": "osm_id",
"key": null
}
...By moving these filters to the import stage with Imposm, We could ensure that each table is pre-optimized for a specific zoom range and removing complex queries from tiler-server.
Improvements for tiles SELECT queries
-
Instead of using the value of a JSONB key in queries, the new config will store those values in their own columns.
tags->'bridge' AS bridge, tags->'start_date' AS start_date, tags->'end_date' AS end_date,
For the above example, it is going to create dedicated columns such as bridge, start_date, and end_date, and extract the corresponding data.
-
Removing filters in the query, since the data is already being filtered during the Imposm stage, we could simplify the SELECT queries. This eliminates unnecessary runtime filtering
- previous
type IN ('water', 'riverbank') AND area > 100000000 AND geometry && !BBOX!
- Updated:
geometry && !BBOX!
-
Removing ST_Simplify fuction: Currently, we use this function to simplify objects and reduce tile sizes for display at specific zoom levels. However, we are moving the simplification functionality to Imposm by utilizing its
toleranceparameter. apply the required simplification during the import stage an reduce y runtime simplification.
For now, I have moved the simplification and filtering process for a few layers to Imposm in Staging , such as water_areas, water_lines, and boundary_lines.I am still working on the other layers, but I hope this approach will help reduce latency issues in the tiler server by pre-processing the data more effectively.
Note:
- Staging use just a few resources so it maybe slow the vtiler, it will better to test in production with large machine.
Happy to hear your thoughts on this new approach. Let me know if you have any suggestions or feedback.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Production
Activity
1ec5 commentedon Nov 30, 2024
This makes plenty of sense to me. We probably need to configure the boundaries a bit differently in imposm for #800 anyhow.
Rub21 commentedon Dec 2, 2024
yes, i think boundaries is the biggest table that we are handling, I am going to work on it
Rub21 commentedon Dec 12, 2024
@1ec5 @danrademacher I have migrated four large tables to imposm: admin boundaries (including centroids), water lines, water areas (including centroids), and transport lines. All simplification processes will now occur in imposm, making the tiler response faster than before. This is because the queries no longer need to process large tables and perform on-the-fly simplifications. The tables are now smaller and contain only the exact types of objects needed for each zoom level
E.g:
Here’s the requested table in Markdown format without the source column:
transport_lines_z5type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction') AND tunnel = 0 AND bridge = 0transport_lines_z6type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link')transport_lines_z7type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed')transport_lines_z8type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed')transport_lines_z9type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed')transport_lines_z10type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed')transport_lines_z11type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed', 'type', 'tram', 'funicular', 'monorail')transport_lines_z12type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed', 'tram', 'funicular', 'monorail', 'taxiway', 'runway', 'raceway', 'residential', 'service', 'unclassified')transport_lines_z13_15type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed', 'tram', 'funicular', 'monorail', 'taxiway', 'runway', 'raceway', 'residential', 'service', 'unclassified')transport_lines_z16_20(type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed', 'tram', 'funicular', 'monorail', 'taxiway', 'runway', 'raceway', 'residential', 'service', 'unclassified', 'subway', 'track', 'living_street', 'footway', 'cycleway', 'path', 'pier', 'steps', 'pedestrian', 'ferry') OR class IN ('railway', 'route'))So almost for each zoom level we have different simplification and filters. The other layers, like water lines, admin boundaries follows the same pattern.
There are still pending other tables/layers to simplify, that we may work in the next weeks, what do you think?
Rub21 commentedon Dec 15, 2024
The issue reported in #923 (comment) was very challenging to identify. In the changeset generated by FK27 had generated several roads, but while some objects (roads) from the changeset appeared in the tiler, one or two did not. I investigated where the error could be, but it took quite some time to figure this out.
https://www.openhistoricalmap.org/way/200679682#

As part of our efforts to improve tiler performance, several adjustments have been made to simplify objects in various tables. However, the issue was related to the number of generalization tables being created in Imposm for transport lines layer, I tables generated for almost every zoom level, because of filter and simplification. (See in the previous comment #917 (comment) )
type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed')type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed', 'type', 'tram', 'funicular', 'monorail')type IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'miniature', 'narrow_gauge', 'dismantled', 'abandoned', 'disused', 'razed', 'rail', 'light_rail', 'preserved', 'proposed', 'tram', 'funicular', 'monorail', 'taxiway', 'runway', 'raceway', 'residential', 'service', 'unclassified') OR class IN ('railway', 'route')It appears that generating multiple generalized tables for each zoom level prevented the insertion of certain objects, even when similar objects from the same changeset were successfully inserted in the database table. After running several tests, I discovered that reducing the number of generalized tables to five, gruped in zoom levels. resolved the issue.
Rub21 commentedon Dec 16, 2024
Since we are using a Hetzner server, the tiler server performs faster than before. However, for some reason, Imposm slows down, and when there are many edits, the tiler falls behind by hours in updating. The reason might be that it needs to update many generalized tables.or network.
e.g in the current time-hours this is the imposm logs
But sequence of minute replication are 858.state.txt
I am going to put this as a high priority, to work today.
cc. @1ec5 @danrademacher @jeffreyameyer
Rub21 commentedon Dec 16, 2024
checking more the logs, some replication files takes 9 minutes to complete update the tiler db
[-]Updating Tiler SQL queries[/-][+]Updating Tiler SQL queries to Materialized view[/+]Rub21 commentedon Jan 6, 2025
Currently, I have migrated a couple of complex queries to Materialized Views, which I believe is the way to go. It provides good response times and improved performance, significantly enhancing the speed of SELECT queries in Tegola vector tiles.
The materialized views are refreshing every 5 minutes with recent changes coming from Imposm. This approach does not interfere with the table updates performed by Imposm, unlike the previous process that relied on triggers and new tables.
The following materialized views have been created, filtering data according to the zoom levels.
Rub21 commentedon Apr 22, 2025
This has been completed for now. Later, we can add more materialized views for other tables, but so far we’ve added them to the heaviest ones!