go-spatial / tegola

Tegola is a Mapbox Vector Tile server written in Go
http://tegola.io/
MIT License
1.28k stars 196 forks source link

Server Very Slow, tile loads took more than 10 seconds. Sometimes browser crashes #460

Closed capan closed 5 years ago

capan commented 6 years ago

I've followed the tutorials and started the server in my local machine. I'm trying to serve country data on my local postgresql server. There is only one layer and in shapefile its size is 10 MB. Everytime I started the server and went to localhost port it took too long for map to load. If I change the zoom levels some tiles never loaded or took too long. Is there any tuning needs to be done in database or tegola configuration ?

My configuration file;

[webserver]
port = ":8080"

[cache]                     # configure a tile cache
type = "file"               # a file cache will cache to the local file system
basepath = "/tmp/tegola"    # where to write the file cache

##register data providers
[[providers]]
name = "citizendb"   # provider name is referenced from map layers
type = "postgis"        # the type of data provider. currently only supports postgis
host = "localhost"      # postgis database host
port = 5433             # postgis database port
database = "citizendb"  # postgis database name
user = "postgres"        # postgis database user
password = "1"          # postgis database password
srid = 3857             # The default srid for this provider. If not provided it will be WebMercator (3857)

  [[providers.layers]]
  name = "tr_iller"
  sql = "SELECT gid, ST_AsBinary(geom_3857) AS geom_3857 FROM public.tr_iller WHERE geom_3857 && !BBOX!"
  geometry_fieldname = "geom_3857"
  id_fieldname = "gid"
  srid = 3857 

[[maps]]
name = "iller" # used in the URL to reference this map (/maps/:map_name)

  [[maps.layers]]
  provider_layer = "citizendb.tr_iller"
  min_zoom = 0
  max_zoom = 20
ARolek commented 6 years ago

@capan first place to check is indexes. Do you have a gist index on your geom_3857 column?

capan commented 6 years ago

Well, yes I have a gist index on geom_3857 but it's still seem to be freezing and some tiles takes 50 seconds to load. Here is a screen record; issue

ARolek commented 6 years ago

@capan from the looks of it the data is pretty fine grained. In this situation I would suggest creating another table with a simplified version of the data via ST_Simplify. This strategy is used with OSM data for layers like water areas. You would then make some modifications to your config file like so:

[webserver]
port = ":8080"

[cache]                     # configure a tile cache
type = "file"               # a file cache will cache to the local file system
basepath = "/tmp/tegola"    # where to write the file cache

##register data providers
[[providers]]
name = "citizendb"   # provider name is referenced from map layers
type = "postgis"        # the type of data provider. currently only supports postgis
host = "localhost"      # postgis database host
port = 5433             # postgis database port
database = "citizendb"  # postgis database name
user = "postgres"        # postgis database user
password = "1"          # postgis database password
srid = 3857             # The default srid for this provider. If not provided it will be WebMercator (3857)

  [[providers.layers]]
  name = "tr_iller_simplified" # new layer with simplification cached.
  sql = "SELECT gid, ST_AsBinary(geom_3857) AS geom_3857 FROM public.tr_iller_simplified WHERE geom_3857 && !BBOX!"
  geometry_fieldname = "geom_3857"
  id_fieldname = "gid"
  srid = 3857 

  [[providers.layers]]
  name = "tr_iller"
  sql = "SELECT gid, ST_AsBinary(geom_3857) AS geom_3857 FROM public.tr_iller WHERE geom_3857 && !BBOX!"
  geometry_fieldname = "geom_3857"
  id_fieldname = "gid"
  srid = 3857 

[[maps]]
name = "iller" # used in the URL to reference this map (/maps/:map_name)

  [[maps.layers]]
  name = "tr_iller"  # use the same layer name to keep the layers together
  provider_layer = "citizendb.tr_iller_simplified"
  done_simplify = true # since you're pre simplifying tell tegola to not apply simplification.
  min_zoom = 0  # note the zoom range
  max_zoom = 10

  [[maps.layers]]
  name = "tr_iller"  # use the same layer name to keep the layers together
  provider_layer = "citizendb.tr_iller"
  min_zoom = 11
  max_zoom = 20

Additionally we have a major update coming to the underlying geo processing part of tegola. If you don't mind compiling from source you should be able to test it out in the v0.7.0 branch later this week and see if you get additional performance improvements.

capan commented 6 years ago

I'm waiting for the update.

wonderchook commented 6 years ago

@capan v0.7.0 is available to try out> https://github.com/go-spatial/tegola/releases/tag/v0.7.0 let us know your results

malexer commented 6 years ago

@ARolek in the maps.layers section you have max_zoom of the first layer equal to the min_zoom of the second one. Is it correct? I guess they should not overlap.

ARolek commented 6 years ago

@malexer good catch. It's actually incorrect. I will modify the above comment.

capan commented 6 years ago

I've tried new version with the same data; browser still freezing from time to time, though I haven't exprienced any black-outs like on the previous version. @wonderchook

capan commented 5 years ago

Problem disappeared in final version.

henhuy commented 3 years ago

Thanks @ARolek for providing example config. One comment: In layer tr_iller it must be dont_simplify not done_simplify - just in case someone stumbles upon this...