spotify / completable-futures

Utilities for working with futures in Java 8
Apache License 2.0
393 stars 51 forks source link

Allow to fail fast when calling joinList. #69

Closed JoseAlavez closed 4 years ago

JoseAlavez commented 4 years ago

Hi spotify devs.

We use this library in combination with Netty, to consume REST APIs that provide us with single fetch contracts (as for example GET /domain/resource/{id}). In other words, when we require to fetch a batch of resources by id, we create individual asynchronous HTTP calls to the respective APIs and then join the completable futures using .collect(CompletableFutures.joinList()).

When our app is under heavy load and our fetch batch logic leads to individual HTTP calls that grows dramatically, we are seeing execution times that are higher than the timeouts specified for each completable future. This is caused due to the capacity of our executor to perform each HTTP call (and queuing) but also because the current implementation of joinList and allAsList utilizes CompletableFuture#allOf, which will wait until all the stages are completed to either continue normally or exceptionally.

I coded a solution for the described matter in https://github.com/spotify/completable-futures/pull/68, but forgot to create an issue, so independently if my contribution gets accepted or not, maybe the improvement can still happen.

Cheers!

JoseAlavez commented 4 years ago

Closing as the only thing pending here is the merge of https://github.com/spotify/completable-futures/pull/68