Bucket stats using Java sdk 3.1

Hi Gourav,

I am using couchbase java sdk to get data from couchbase bucket. But it is getting TIMED OUT.

Are you getting a timeout exception from the SDK (indicating the server is taking too long to run the query), or is your Java code just taking too long to run? If it’s a timeout exception, I would recommend starting a new thread in the N1QL forum so the experts see it and can help tune the query.

If your question is how to make the Java code run faster, I can offer some tips.

  • Create a single ObjectMapper and reuse it. A Jackson ObjectMapper is thread-safe after configuration.

  • OR… instead of using your own ObjectMapper, let the SDK convert the result rows to a Map for you:

List<Map<String, Object>> list = result.rowsAs(
    new TypeRef<Map<String, Object>>() {}
);
  • The code you shared uses the blocking Query API, and stores the entire result set in memory. If the result set is very large, it may be more efficient to use the Reactive API to process each result row as it arrives from the server. See Async and Reactive APIs | Couchbase Docs

EDIT: Sorry, I failed to notice you already shared the stack trace for the AmbiguousTimeoutException. I would definitely post in the N1QL forum to see if it’s possible to optimize the query.

Thanks,
David