Open Bucket slow connection

I’m testing Couchbase 4.0 and 4.1 on seperate servers and noticed for the c# client that open bucket is taking a very long time. One instance is Couchbase 4.0 with 2 nodes on an azure vpn which the web app is connected to. Another is a single node with couchbase 4.1 and running locally.

Is this a known issue? I’m currently using the following for my connections:

web.config:

c# data class:

using (var cluster = new Cluster(“couchbaseClients/couchbase”))
{
IBucket bucket = null;
try
{
bucket = cluster.OpenBucket(bucketName);

                string query = String.Format("select id, name, email, department, title, phoneNumber, roles, accessFailedCount from `{0}` where type = \"{1}\";", bucketName, CouchbaseConstants.DocumentType.User);
                var queryRequest = new QueryRequest().Statement(query);

                var result = bucket.Query<ApplicationUser>(queryRequest);

                if (result.Success)
                {
                    companyUsers = result.Rows;
                }
                else
                {
                    error = result.Message;
                }
            }
            catch (Exception ex)
            {
                error = String.Format(ServiceConstants.Response.Exception, ex.Message);
            }
            finally
            {
                if (bucket != null)
                {
                    cluster.CloseBucket(bucket);
                }
            }
        }

@schuranator -

No known issues that I am aware of, can you post your config (don’t post any sensitive info ;)) and perhaps enable logging? http://developer.couchbase.com/documentation/server/4.0/sdks/dotnet-2.2/setting-up-logging.html

-Jeff

I’m not sure if it’s maybe the way I setup my datalayer or how I’m using my web.config:

  <couchbaseClients>
<couchbase useSsl="false">
  <servers>
	<add uri="http://165.225.158.19:8091/pools"/>
	<add uri="http://165.225.154.17:8091/pools"/>
	<add uri="http://199.192.240.16:8091/pools"/>
  </servers>
  <buckets>
	<add name="default" useSsl="false" password="">
	  <connectionPool name="custom" maxSize="100" minSize="5" sendTimeout="2000" />
	</add>
  </buckets>
</couchbase>
</couchbaseClients>

Now I am using ClusterHelper in my global.asx but in my DataLayer I’m just using the following code not sure if this is correct:

	using (var cluster = new Cluster("couchbaseClients/couchbase"))
{
	IBucket bucket = null;
	try
	{
	    bucket = cluster.OpenBucket(bucketName);

	    string documentID = string.Format(CouchbaseConstants.DocumentID.Company, companyID);
	    var document = bucket.GetDocument<Company>(documentID);

	    if (document.Success)
	    {
	        company = document.Content;
	    }
	    else
	    {
	        error = document.Message;
	    }
	}
	catch (Exception ex)
	{
	    error = String.Format(ServiceConstants.Response.Exception, ex.Message);
	}
	finally
	{
	    if (bucket != null)
	    {
	        cluster.CloseBucket(bucket);
	    }
	}
}

Also I’m noticing when I do a remove or insert lets say on Company if I’m using multiple buckets 98% of the time it doesn’t show that change unless I do a hard refresh. Is there something on my end I can do to make sure the changes have applied to all the nodes?

When using one node the above Company Insert/Update/Remove doesn’t have any issues.

[quote=“schuranator, post:3, topic:6269”]
<connectionPool name=“custom” maxSize=“100” minSize=“5” sendTimeout=“2000” />[/quote]

If you are using ClusterHelper in your global.asax, why wouldn’t you being using it in your data layer? Just make your data layer classes implement a ctor that takes an IBucket reference and using ClusterHelper.GetBucket() to inject the dependency.

The problem with the code you have here is that the Cluster and Bucket will be created every time this code runs; what you want to do is create the Cluster and Bucket when the application starts and close/dispose when it ends. Using ClusterHelper helps here, read this: Couchbase SDKs

I not 100% sure I understand you here…buckets are shared across clusters. When you do write, the document is immediately available from the primary unless you are doing a replica read without durability constraints. That being said, for a N1QL query there is a small amount of time before the documents will be returned in the results because the value may not have yet been indexed. Read this post: N1QL - is there delay like a view query?

-Jeff