Huge performance hit in sync function when calling access()

I noticed that there is a huge slowdown in my sync function when saving documents if I call the access() function in my sync function. Without calling access() I can save a hundred documents in less than 5 seconds. If I make a call to access() in the sync function it takes over a minute to schedule the same number of documents. This is on sync gateway v1.1.0, running on an ubuntu 12.0.4 box (4 2.0GHz CPU, 7GB RAM, but also running couchbase server at the same time). I’m calling access like this(both input params are strings):

access(doc.userId,doc.timeChannel);

I tried with users that already have a few dozen channels and users with less than 5 channels and the functionality was the same.

I checked the sync gateway documentation and didn’t see a way to check if a specified user already has access to a channel, but is there a fast call I can make to see if the specified user (not the current user) already has access to that channel?

Calling access() is a relatively expensive operation, particularly when targeting the current user, as Sync Gateway needs to recalculate the current user’s channel set after the change. There isn’t a way to check whether a user already has access within the sync function - that scenario would run into problems if whatever other document is granting the user access was modified.

Even considering the computational work access() needs to do, that performance still sounds slower than I would have expected. What version of Couchbase Server are you using?

I’m using couchbase server enterprise v3.0.2

I’m calling access on a different user, as specified by doc.userId, not the current user.

There is a known performance issue when using Couchbase Server 3.0.2 related to access() calls - I expect that’s responsible for some of the performance degradation you’re seeing. This is the main reason Sync Gateway 1.1.0 isn’t officially marked for compatibility with 3.0.2 (see http://developer.couchbase.com/mobile/develop/references/sync-gateway/release-notes/1.1.0/index.html for details).

I expect you’ll see improved performance with Couchbase Server 3.1.0, which is believe is targeted for release in the very near future.