agrestio / agrest

Server-side Java REST Framework for easy access to data graphs from various backends
https://agrest.io
Apache License 2.0
81 stars 34 forks source link

Parallel resolvers #431

Open andrus opened 5 years ago

andrus commented 5 years ago

Now that we have a universal and flexible resolver lifecycle (#413), let's figure out how to build resolvers working in parallel. Each resolver knows whether it needs to wait for the parent to complete before firing up, so I think we can create a simple framework that can allow arbitrary resolvers to decide whether they are sequential or parallel and execute accordingly. E.g. ViaQueryWithParentQualifierResolver (the default nested resolver) can totally work in parallel.

andrus commented 1 year ago

The simplest approach would be to redo RelatedDataResolver.onParentDataResolved method to take a CompletionStage<Iterable> for parent data:

void onParentDataResolved(
   RelatedResourceEntity<T> entity, 
   CompletionStage<Iterable<?>> parentData, 
   SelectContext<?> context);

In this case maybe we won't even need RelatedDataResolver.onParentQueryAssembled, simplifying the design. With this API the child can decide whether to do something after the parent is resolved, or do something right away in parallel.

TODO: need a benchmark to estimate the cost of wrapping everything in ComletionStage.