Slow connection to Couchbase 6.5

I’ve just downloaded the Couchbase 6.5 Beta. It didn’t seem to be obviously compatible with the 2.5 Java SDK (I can post separately on that if that should, in fact, work) so I downloaded the 3.0beta.2 SDK.

I just wrote basically the first line of the tutorial, and ran it and it seems to reliably take 16s to connect to the server running on localhost. I browsed the forums and saw some things about reverse DNS but nothing that seemed to say “do this”.

Needless to say, this is very annoying. What can I do?

Code:

	logger.info("hello world");
Cluster cluster = Cluster.connect("localhost", "test", "password");
logger.info("connected");

Log:
20191231-15:04:20.121 Test/in INFO: hello world
20191231-15:04:20.334 gers$LoggerFactory/in DEBUG: Using Slf4j logging framework
20191231-15:04:36.059 com.couchbase.core/ts INFO: [com.couchbase.core][CoreCreatedEvent] {“clientVersion”:“3.0.0-beta.2”,“clientGitHash”:“d55dc8af”,“coreVersion”:“2.0.0-beta.2”,“coreGitHash”:“d55dc8af”,“userAgent”:“couchbase-java/3.0.0-beta.2 (Mac OS X 10.15.2 x86_64; Java HotSpot™ 64-Bit Server VM 1.8.0_211-b12)”,“ioEnvironment”:{“nativeIoEnabled”:true,“eventLoopGroups”:[“KQueueEventLoopGroup”]},“ioConfig”:{“captureTraffic”:,“mutationTokensEnabled”:true,“networkResolution”:“auto”,“dnsSrvEnabled”:true,“tcpKeepAlivesEnabled”:true,“tcpKeepAliveTime”:{“seconds”:60,“zero”:false,“negative”:false,“units”:[“SECONDS”,“NANOS”],“nano”:0},“configPollIntervalMillis”:2500,“kvCircuitBreakerConfig”:“disabled”,“queryCircuitBreakerConfig”:“disabled”,“viewCircuitBreakerConfig”:“disabled”,“searchCircuitBreakerConfig”:“disabled”,“analyticsCircuitBreakerConfig”:“disabled”,“managerCircuitBreakerConfig”:“disabled”,“numKvConnections”:1,“maxHttpConnections”:12,“idleHttpConnectionTimeout”:{“seconds”:300,“zero”:false,“negative”:false,“units”:[“SECONDS”,“NANOS”],“nano”:0}},“compressionConfig”:{“enabled”:true,“minRatio”:0.83,“minSize”:32},“securityConfig”:{“tlsEnabled”:false,“nativeTlsEnabled”:true,“hasTrustCertificates”:false,“trustManagerFactory”:null},“timeoutConfig”:{“kvMs”:2500,“kvDurableMs”:10000,“managementMs”:75000,“queryMs”:75000,“viewMs”:75000,“searchMs”:75000,“analyticsMs”:75000,“connectMs”:10000,“disconnectMs”:10000},“loggerConfig”:{“customLogger”:null,“fallbackToConsole”:false,“disableSlf4j”:false,“loggerName”:“CouchbaseLogger”,“diagnosticContextEnabled”:false},“diagnosticsConfig”:{“enabled”:false,“emitInterval”:“PT30M”},“retryStrategy”:“BestEffortRetryStrategy”,“requestTracer”:“OwnedSupplier”} {“coreId”:1}
20191231-15:04:36.064 com.couchbase.node/ts INFO: [com.couchbase.node][NodeConnectedEvent] Node connected {“coreId”:1,“managerPort”:“8091”,“remote”:“localhost”}
20191231-15:04:36.065 .couchbase.service/ts DEBUG: [com.couchbase.service][ServiceConnectInitiatedEvent] Starting to connect service with 1 minimum endpoints {“coreId”:1,“remote”:“localhost:11210”,“type”:“KV”}
20191231-15:04:36.067 couchbase.endpoint/ts DEBUG: [com.couchbase.endpoint][EndpointStateChangedEvent] Endpoint changed state from DISCONNECTED to CONNECTING {“circuitBreaker”:“DISABLED”,“coreId”:1,“remote”:“localhost:11210”,“type”:“KV”}
20191231-15:04:36.067 .couchbase.service/ts DEBUG: [com.couchbase.service][ServiceStateChangedEvent] Service changed state from DISCONNECTED to CONNECTING {“coreId”:1,“remote”:“localhost:11210”,“type”:“KV”}
20191231-15:04:36.067 com.couchbase.node/ts DEBUG: [com.couchbase.node][NodeStateChangedEvent] Node changed state from DISCONNECTED to CONNECTING {“coreId”:1,“managerPort”:“8091”,“remote”:“localhost”}
20191231-15:04:36.149 Test/in INFO: connected

@gareth it might be DNS SRV - can you change it in the IoConfig to false and see if the situation improves (on the cluster options in the ClusterEnvironment) ? (alternatively if you specify 127.0.0.1 instead it should also not try dns resolution)

I used to be able to do these configurations by passing an environment to CouchbaseCluster.fromConnectionString(). This doesn’t appear to be the case in the new SDK.

Is creating an environment enough by itself?

	CoreEnvironment.Builder ceb = CoreEnvironment.builder();
	ceb.ioConfig().enableDnsSrv(false);
	CoreEnvironment env = ceb.build();
	cluster = Cluster.connect("localhost", "test", "password");

This didn’t make any difference, so I went on to create a Core from this:

	Set<SeedNode> seedNodes = new HashSet<>();
	seedNodes.add(SeedNode.create("localhost"));
	Core core = Core.create(env, PasswordAuthenticator.create("test", "password"), seedNodes);
	core.openBucket("ziniki-unit");

The openBucket here appears to all work “immediately”, but I don’t see how to connect this to the rest of the API and the ensuing Cluster code I had previously does not improve at all.

20200101-09:29:25.157               Test/in INFO: hello world
...
20200101-09:29:26.321 com.couchbase.core/ts INFO: [com.couchbase.core][BucketOpenedEvent][499040µs] Opened bucket "ziniki-unit" {"coreId":1}
20200101-09:29:41.010               Test/in INFO: connected

@gareth in SDK 3 you want to do it like this:

    ClusterEnvironment env = ClusterEnvironment.builder().ioConfig(IoConfig.enableDnsSrv(false)).build();
    Cluster cluster = Cluster.connect(
      "localhost",
      clusterOptions("test", "password").environment(env)
    );
Bucket bucket = cluster.bucket("ziniki-unit");
Collection collection = bucket.defaultCollection();

That works perfectly. Thanks.