I did some Tests with this Setup and noticed a pretty huge slowdown caused by concatMap
If someone googles this and does not require the order use flatMap
Test:
- Localhost, 4.0.0-2213 DEV Edition (build-2213), no memory Limits
- .requestBufferSize(131072) (High enough to not result in any BackPressureExceptions)
- At the end i wait for multiple view-Queries to finish:
while (!accountSub.isUnsubscribed() || !userSub.isUnsubscribed() || !regionSub.isUnsubscribed()) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } }
Old Code or new Code with .flatMap. About 30k-50k OPS + 20k Ops of the last Data-View
Basically this is bound by my CPU-Speed. The Java-App + CB take 99%
(Slowdown at the end caused by a view-Query that is dependent on another query to finish first)
With BackPressure-Checks and .concatMap. About 25k OPS + 20k Ops of the last Data-View
This is no longer bound by my CPU-Speed. The Java-App + CB take 65%**
(Slowdown at the end caused by a view-Query that is dependent on another query to finish first)
Code Example
asyncBucket.query(ViewQuery.from("getAll", "regions").stale(Stale.FALSE)) .flatMap(x -> x.rows()) .**concatMap**(row -> { return Observable.defer(() -> row.document()) .retryWhen(RetryBuilder.anyOf(BackpressureException.class) .max(5) .delay(Delay.exponential(TimeUnit.MILLISECONDS, 500, 1)).build()); }) .map(doc -> Region.fromJson(doc.content())).toBlocking().forEach(region -> regions.put(region.getName(), region));