N1ql Performance issue with JAVA SDK

Hi ,
I am trying to get some result using couchbase N1QL query.However, when i am running a select query on server it is taking around 0.5 seconds but when i am running it via java SDK client then it is taking around 13 to 15 seconds for displaying result on console. is there any other way to boost performance using JAVA SDK? Any help would be greatly appreciated. Here is code snippet

		Cluster cluster = CouchbaseCluster.create(cbConnectionString,cbUser,cbPassword);
		
		Bucket bucket = cluster.openBucket(bucketName,12000, TimeUnit.MILLISECONDS);

		String queryText = "SELECT productName,productId FROM bucket1 WHERE docType = 'product' and reportableInd = '1'
				
		N1qlQueryResult queryResult = bucket.query(N1qlQuery.simple(queryText));
		for (N1qlQueryRow n1qlQueryRow : queryResult) {
			list.add(n1qlQueryRow.toString())				
			System.out.println(list);

Is the query taking 12 seconds or is it also the bucket opening that takes time in your case?

Can you measure just the query execution?

Yes bucket also takes time ,when i run that piece of code to know the time measure it takes i get this result
01:43:50:685 INFO CouchbaseConnection main Performance - bucket opening time=8.540 seconds
01:43:54:249 INFO CouchbaseConnection main Performance - Get Product List=12.167 seconds

Let me tell you that there are around 9000 items in a list, previously i was guessing this is happening because of bulk data ,but , when i connect the same with SQL server and run sql query it was hardly taking 2 seconds ,this is a big difference. Should i change the approach of fetching data or there is an alternative for N1QL?

Well, we need to fix the bucket open first since that alone shows there is a environmental problem somewhere.

When you execute a N1QL query on the UI you run it on the same server in the datacenter, is your client far away from the servers? 8s is a veeeery long time to open a bucket, normally this is way under a second.

No ,Application and datacenter are not on the same server. But, they are on the same network. When I ping the datacenter server from my machine it takes less than a millisecond to respond.

Pinging Server1.abc.com [xx.xx.xxx.xxx] with 32 bytes of data:
Reply from xx.xx.xxx.xxx: bytes=32 time<1ms TTL=63
Reply from xx.xx.xxx.xxx: bytes=32 time=1ms TTL=63
Reply from xx.xx.xxx.xxx: bytes=32 time<1ms TTL=63
Reply from xx.xx.xxx.xxx: bytes=32 time<1ms TTL=63

Ping statistics for xx.xx.xxx.xxx:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms

@mini okay thanks thats good to know. Next step: can you please enable TRACE logging in your logger with dates and times so we can see where the time is spent? If you don’t want to share that log publicly you can email it to me - I’ll DM you my addy.

Yeah. i will
Thanks a lot for your help :slight_smile: