CompletableFuture to Flowable

To maintain backward compatibility in our code, we want to convert CompletableFuture to Flowable(for get, it should be Single, but the code was written in that fashion). This is how we have written the code but it is taking around 30-40ms for the get call. Any suggestions to improve the same ? The same code is getting executed for around 1M request while doing the performance testing.

Flowable.fromFuture(primaryAsyncBucket
              .defaultCollection()
              .get(key, GetOptions.getOptions().withExpiry(true).retryStrategy(FailFastRetryStrategy.INSTANCE)))
              .map(getResult -> new JsonDocument(key, getResult.contentAsObject(), getResult.cas(), getResult.expiry().get()))
              .switchIfEmpty(Flowable.error(new NoSuchElementException(key + " Not Found")));

The results are not from cold boot. The JVM is warmed up with around 50000 requests before starting the test. The test are ram on OpenJDK 11, RxJava3, Vert.x and Couchbase server version 6.6

Hi @himanshu.mps
Well the code looks fine to me. There’s a few go-to things I’d check on read performance:

  • What is your network latency from the appserver to the cluster?
  • How long does a profiler indicate the JSON decode taking? (As a side discussion, part of why we moved the JSON decode out of our the library and into ‘user space’ is to make it easier for devs to measure that cost, which can be significant.)
  • How large are the documents? Can you use Sub-Document to fetch smaller pieces of them?

After that, if it were me, I would be following my usual checklist. (Technically that’s for debugging timeouts, but it has strong overlap with investigating performance.)

1 Like

@graham.pople I think I did figure out the issue. I am running the server on one core and it was creating one thread for forjoinpool. Increasing the parallelism for it did the trick.

2 Likes