Using rxjava observable collection issue

We try to get data from couchbase by using Rxjava as the tutorial recommended, below is the code:

public List batchGet(final Collection ids) {
return Observable
.from(ids)
.flatMap(new Func1<String, Observable>() {
@Override
public Observable call(String id) {
return bucket.async().get(id);
}
})
.toList()
.toBlocking()
.single();
}

But we found if the Collection ids is big enough(50k), it will cause a out of memory Exception, then we change the code and invoke this method serval times to avoid the exception.

If there an recommended observable collection size? Our test results shows if collection size is 10K will costs 1.5 seconds each time and 20K size costs about 2.2 seconds.

Thank you very much.

Can you share the exact exception you get and maybe some code to reproduce? There might be different exceptions thrown (especially a BackpressureException if you overload the request ringbuffer with a huge batch). And depending on what happens they might need to be treated differently. Maybe you can show us some logs as well?