Hi all, i recently installed my own OSM Tileserver on a very capable machine, expecting the performance to be quite good. Unlucky for me, most tiles even at high zoom levels take much too long for a smooth user interaction. I will append information about the system and used software below. I found the actual slow part to be the Database, particulary some queries involving postgis functions on larger geometries. An example is the following query:
The actual slow part seems to be, much to my surprise, the ST_IsValid and ST_PointOnSurface function, which take ~400ms each on a geometry that contains 134283 points. The question now is, can i - and how - reduce the time spent for those queries? 400ms for ST_IsValid seems unreasonable to me. Any help is much appreciated. Stats and diagnostics I used the very nice tutorial at: http://switch2osm.org/serving-tiles/manually-building-a-tile-server-14-04/ Server specs:
Software used:
Mapnik style:
PostgreSQL configuration:
asked 30 Jan '15, 17:45 markusd |
I've noticed the same problem with our tile server. Queries which use ST_PointOnSurface and ST_IsValid -- even in combination with a bounding box -- take several seconds to run, which kills our rendering performance. I found an intro to PostGIS on Boundless which states, "ST_PointOnSurface(geometry) returns a point that is guaranteed to be inside the input argument. It is substantially more computationally expensive than the centroid operation." In my testing, I found that replacing ST_PointOnSurface with ST_Centroid and removing ST_IsValid from the query can result in about a 10-fold performance gain (396 ms vs 4533 ms for my test query, which is similar to the one in the question above). The problem with changing to ST_Centroid is that the centroid of a polygon may not fall within its bounds. I ran a couple of queries to see how many OSM polygons with labels have a centroid outside of their bounds:
It appears that roughly 4% of the labeled polygons do not contain their centroid. Alternate queriesIf speed is the most important consideration in rendering, you can rework your query to output the centroid of the geometry as follows:
The following form of the query uses the centroid when it is inside the polygon and ST_PointOnSurface when it is outside. It will always return a point within the polygon, at the cost of a little extra processing time:
In my measurements, the first query is about 10x as fast as the original, and the second about 5x as fast. We are planning to try the faster query on our tile servers. If the label placement looks strange, we will probably switch to the second version to see if there is any improvement. answered 07 Jun '16, 18:09 pegli |