Sync gateway grant access process 1 record over a second (N1QL Query(“access”) took 5.1292934s)

Hello Couchbase Lover ,

I am using a community version Couchbase Server, Sync Gateway, Couchbase Lite, and Talend Open Studio to handle mobile synchronization interact with PostgreSQL.

Here is my problem, I found out I transfer the 10K data from PostgreSQL to Couchbase Server, then Sync Gateway is started to grant channel access. But somehow it working like a 1 record over a second, it drives me crazy how come is slow.

I referred to this article : Query: N1QL Query("access") took 49.609624065s

It looks like is the query issue, but index ram is already increased.

Any guys can help me to find out the root cause?

Log below

2020-12-17T15:29:22.886+08:00 [INF] Query: N1QL Query(“access”) took 5.1292934s
2020-12-17T15:29:22.988+08:00 [INF] Access: Recomputed channels for “sync”: !:1,*:2,fb_item:2
2020-12-17T15:29:22.989+08:00 [INF] Access: Invalidate access of “sync”
2020-12-17T15:29:22.990+08:00 [INF] Auth: Saved principal w/ name:sync, seq: #2
2020-12-17T15:29:22.996+08:00 [INF] CRUD: Doc “0000000007467” / “1-aa842e873399032202ce6a3b6ac060f8” in channels “{fb_item}”
2020-12-17T15:29:22.996+08:00 [INF] Access: Doc “0000000007467” grants channel access: map[sync:fb_item:7613]
2020-12-17T15:29:22.998+08:00 [INF] Access: Rev “0000000007467” / “1-aa842e873399032202ce6a3b6ac060f8” invalidates channels of [sync]

2020-12-17T15:29:27.978+08:00 [INF] Query: N1QL Query(“access”) took 4.9752846s
2020-12-17T15:29:28.040+08:00 [INF] Access: Recomputed channels for “sync”: !:1,*:2,fb_item:2
2020-12-17T15:29:28.040+08:00 [INF] Access: Invalidate access of “sync”
2020-12-17T15:29:28.047+08:00 [INF] Auth: Saved principal w/ name:sync, seq: #2
2020-12-17T15:29:28.048+08:00 [INF] DCP: Backfill in progress: 31% (10749 / 33976)
2020-12-17T15:29:28.051+08:00 [INF] CRUD: Doc “000000000A118” / “1-3e1963891d7ceec7ba112273f53d9808” in channels “{fb_item}”
2020-12-17T15:29:28.051+08:00 [INF] Access: Doc “000000000A118” grants channel access: map[sync:fb_item:7614]
2020-12-17T15:29:28.053+08:00 [INF] Access: Rev “000000000A118” / “1-3e1963891d7ceec7ba112273f53d9808” invalidates channels of [sync]

Server setup


Sync Gateway Settings
{
  "log": ["*"],
  "databases": {
    "fb_item": {
      "server": "http://localhost:8091",
      "bucket": "fb_item",
      "username": "Admin", 
      "password": "password", 
      "enable_shared_bucket_access": true, 
      "import_docs": true,
	  "num_index_replicas": 0,
	  "users":{
		"GUEST": {"disabled": true},
		"sync": {"password": "password", "admin_roles": ["syncRole"], "admin_channels": ["*", "fb_item"]}
	  },
	  "sync": `function (doc, oldDoc) { 
		channel("fb_item");
		access("sync","fb_item")
	  }`,
	  "roles": {"syncRole": {"admin_channels": ["*"]}}
    }
  }
}

Problem solved, the issues is I added access(“sync”, “fb_item”), but the sync gateway is not log-in with this account, then would cause authentication warning each record.

Would recommend familiarizing with our Access Control and User Authentication concepts .

Unrelated to the issue that you have figured out, there is an anti-pattern in your config definition -
You have statically defined a user named “sync” (within your users config) who is granted access to “fb-item” channel. So there is no reason to grant access once again via the “access” function in your sync function. “access” is an expensive operation and there will be a performance overhead if you make that redundant call for every document that is processed by your sync function. So remove that “access()” call from within your sync function - you will use that for dynamic access grants.