I am using NodeJS SDK. In the basic sample that follows I am opening a bucket to insert a single record. I have put each method in a promise to force them run one after another (sequentially) so I can measure each method’s running time.
My OS: Ubuntu 16.04
'use strict';
const couchbase = require('couchbase');
const cluster = new couchbase.Cluster('couchbase://localhost');
const uuid = require('uuid/v4');
console.time('auth');
cluster.authenticate('administrator', 'adminadmin');
console.timeEnd('auth');
function open() {
return new Promise((resolve, reject) => {
console.time('open');
let bucket = cluster.openBucket('test', function (err) {
if (err) {
console.error(err);
reject(err);
}
resolve(bucket);
});
});
}
function insert(bucket, obj) {
return new Promise((resolve, reject) => {
console.time('upsert');
bucket.upsert(`uuid::${blog.name}`, blog, function (err, result) {
if (err) {
console.log(err);
reject(err);
}
resolve(bucket);
});
});
}
function dc(bucket) { // disconnect
return new Promise((resolve, reject) => {
console.time('dc');
bucket.disconnect();
resolve('ok');
});
}
// data to insert
let blog = {
id: uuid(),
name: 'Blog A',
posts: [
{
id: uuid(),
title: 'Post 1',
content: 'lorem ipsum'
}
]
};
open().then((bucket) => {
console.timeEnd('open');
insert(bucket, blog).then((bucket) => {
console.timeEnd('upsert');
dc(bucket).then((res) => {
console.timeEnd('dc');
console.log(res);
});
});
});
The output is:
auth: 0.237ms
open: 58117.771ms <--- this shows the problem
upsert: 57.006ms
dc: 0.149ms
ok
I ran sdk-doctor. It gave me two lines worth mentioning:
and the summary is:
Summary: [WARN] Your connection string specifies only a single host. You should consider adding additional static nodes from your cluster to this list to improve your applications fault-tolerance
Would anyone please help?
According to this answer in the Couchbase forum, it seemed that my DNS servers were not configured properly.
It looks as though your DNS servers may be configured improperly. As part of the normal bootstrap procedure, we attempt to resolve SRV records for the hostname that is provided, it looks like you’re DNS servers may be timing out when trying to do this, causing a substantial delay when connecting. A quick way to test this theory is to add an additional hostname to your bootstrap list to disqualify the connection string from our DNS-SRV policy (for instance, use: couchbase://localhost,invalidhostname).