Skip to content

Eager vs Lazy prefetch #1397

@bsideup

Description

@bsideup

In current version of Reactor ( 3.2.1.RELEASE ), this code will do request(100) (because of eager prefetch):

Flux.range(0, Integer.MAX_VALUE)
        .hide()
        .log("producer")
        .concatMap(Mono::just, 100)
        .log("subscriber")
        .subscribe(new Subscriber<>() {
            @Override
            public void onSubscribe(Subscription s) {
            }

            @Override
            public void onNext(Integer integer) {

            }

            @Override
            public void onError(Throwable t) {

            }

            @Override
            public void onComplete() {

            }
        });

// 11:25:40.166  INFO   --- producer   : onSubscribe(FluxHide.HideSubscriber)
// 11:25:40.182  INFO   --- subscriber : onSubscribe(FluxConcatMap.ConcatMapImmediate)
// 11:25:40.184  INFO   --- producer   : request(100)

Suggestion:
Optional prefetch mode, LAZY|EAGER. If it is LAZY, there will be no prefetch unless downstream does it's first request.

Motivation:
While it's ok for most of use cases, it might be a big issue when the publisher is some IO source (e.g. Kafka, RSocket, etc), where requesting before the subscriber is ready to consume is a waste of resources and might affect the startup time of the app if there are some global publishers (e.g. message processing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/gen4Possible research theme for Reactor 4status/on-holdThis was set aside or cannot be worked on yet

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions