Problem with spatial view performance

I am using a spatial view for getting a group of objects by their coordinates. I started with an empty bucket which was growing over a time. In the beginning it had nice response times, but after few days, when bucket reached about 2 mln objects the spatial view started to behave really badly. From ~200 ms response time it unexpectedly went to around few seconds (it’s not visible in the plot because in my application I break the connection if response time is over 1.5s)
I have 3 nodes in my cluster and it still has 25% of RAM unused. The plot below shows mean couchbase spatial view REST API response times during first week of my application.

Here is my spatial view function

function (doc) {
  if (doc.geoLocation) {
    geojson = {};
    geojson.type = "Point";
    geojson.coordinates = [doc.geoLocation.lat, doc.geoLocation.lon];
    emit( geojson, doc );
  }
}

Do you have any idea why the performance became so bad, and what can I do to improve it?

1 Like

We had a similar issue with geospatial views on Couchbase and switched then to elastic search which did the job of finding locations within a distance with a more predictable behaviour. However, would be great to see a better working solution for Couchbase.

@Plendemulo what I’m seeing from your code here is that you are storing the full doc as the value in the index, which is not a good idea. This means the full doc content will be stored both in the KV store and in the index which blows it up by a huge amount and is unnecessary. If you need the full document the approach you want to go with is emit null in the index itself which keeps it nice and small and then fetch the documents via KV on the client side - we can show you how easily depending on the choice of SDK.

@scotrix if this is the same code for you then this might help you too.