Question

I'm working on a google maps application along with Postgresql and PostGIS that fetches markers based on the current viewport of the map and the zoom level (each marker has a min and max zoom level for which they will be fetched). The query runs in anywhere from 50 to 300 ms. However, processing in the views consistently takes over 1200 ms and often takes up to 4000 ms. Here's an example of the output from the query:

Completed 200 OK in 3997ms (Views: 3800.2ms | ActiveRecord: 195.7ms)

I'm using ActiveModelSerializers and tweaking with the fields returned yields slight benefits (ex. removing a description field which can get long), but nothing all that significant. There seems to be something in the pipeline that is taking an exorbitant amount of time. Does anyone have any ideas where this may be occurring?

EDIT:

We're using Postgres version 9.3. Here is the dump from EXPLAIN ANALYZE:

[["Aggregate  (cost=9467.65..9467.66 rows=1 width=0) (actual time=76.429..76.429 rows=1 loops=1)"],
["  ->  Bitmap Heap Scan on markers  (cost=2734.88..9457.31 rows=4136 width=0) (actual time=63.436..76.026 rows=4135 loops=1)"],
["        Recheck Cond: ((5 >= min_zoom) AND (point && '010300002...'::geography))"],
["              ->  Bitmap Index Scan on index_markers_on_min_zoom  (cost=0.00..983.17 rows=67833 width=0) (actual time=14.185..14.185 rows=68500 loops=1)"],
["              ->  Bitmap Index Scan on index_markers_on_point  (cost=0.00..1749.39 rows=67064 width=0) (actual time=38.530..38.530 rows=66232 loops=1)"],
["                    Index Cond: (point && '0103000020E610.....'::geography)"],
["Total runtime: 77.015 ms"]] 

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top