1
votes

I have Couchbase community edition v4, build 4047. Everything seems to be great with it until I started issuing queries against a simple view. The view is just projecting the documents like so, which seems harmless:

function (doc, meta) {
  if(doc.applicationId){
   emit(doc.applicationId,meta.id); 
  }
}

I'm using the .Net client to connect and execute the query from my application, though I don't think that matters. It's a single node configuration. I'm clocking time in between the actual http requests and the queries are taking between 4 seconds up to over 2 minutes if I send something like 15 requests in at a time through Fiddler.

I am using a stale index to try and boost that time, but it doesn't seem to have much impact. The bucket is not very large. There are only a couple of documents in the bucket. I've allocated 100M RAM for indexing. I'd think that's fine for at least the few documents we're working with at the moment.

This is primarily local development, but we are observing similar behaviors when promoted to our servers. The servers don't use a significant amount of RAM either, but at the same time we aren't storing a significant amount of documents. We're only talking about 10 or 20 at the most? These documents only contain like 5 primitive-type properties.

Do you have some suggestions for diagnosing this? The logs through the couchbase admin console don't show anything unusual as far as I can tell and this doesn't seem like normal behavior.

Update: Here is my code to query the documents

        public async Task ExpireCurrentSession(string applicationId)
        {
            using (var bucket = GetSessionBucket())
            {
                var query = bucket
                    .CreateQuery("activeSessions", "activeSessionsByApplicationId")
                    .Key(applicationId)
                    .Stale(Couchbase.Views.StaleState.Ok);

                var result = await bucket.QueryAsync<string>(query);

                foreach (var session in result.Rows)
                {
                    await bucket.RemoveAsync(session.Value);
                }
            }
        }
1
Could you post the c# code snippet you use for querying the index? In particular, how you create and add parameters to the QueryView arg. Also, why are you emitting meta.id as the value? The view emits the id of the original document into the index automatically anyway (each row result you get from the query has an Id property.) - David Ostrovsky
Hi David, I posted the code that queries. As far as why I extract the id when it's already part of the document is because I really didn't want the entire document. It wasn't necessary to transmit everything. I just wanted to pull the ids for everything that contained a specific application Id. Thanks. - Fratt

1 Answers

0
votes

The code seems fine, and should work as you expect. The 100mb RAM you mention allocating actually isn't for views, it only affects N1QL global secondary indexes. Which brings me to the following suggestion:

You don't need to use a view for this in Couchbase 4.0; you can use N1QL to do this simpler and (probably) more efficiently.

Create a N1QL index on the applicationId field (either in code of from the cbq command line shell) like so:

CREATE INDEX ix_applicationId ON bucketName(applicationId) USING GSI;

You can then use a simple SELECT query to get the relevant document IDs:

SELECT META(bucketName) FROM bucketName WHERE applicationId = '123';

Or even simpler, you can just use a DELETE query to delete them directly:

DELETE FROM bucketName WHERE applicationId = '123';

Note that DML statements, like DELETE are still considered a beta feature in Couchbase 4.0, so do your own risk assessment.

To run N1QL queries from .NET you use almost the same syntax as for views:

await bucket.QueryAsync<dynamic>("QUERY GOES HERE");