-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance RestMulti, configurable demand + distinct objects #38801
Conversation
@geoand there it is. Haven't added tests yet (hence it's still a draft-PR). |
} | ||
}); | ||
} | ||
} | ||
|
||
private static class ChunkedStreamingMultiSubscriber extends StreamingMultiSubscriber { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this inner class, because it's doing what StreamingMultiSubscriber
does with encodeAsJsonArray==false
Nice! |
6db9089
to
b2dd31d
Compare
Added test cases and updated docs |
b2dd31d
to
1cfe6f5
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🙈 The PR is closed and the preview is expired. |
Adds two enhancements: 1. Produce multiple JSON objects, not just an array 2. Make requested demand configurable == Produce multiple JSON objects Currently, `PublisherResponseHandler.StreamingMultiSubscriber` produces a JSON array, where each emitted item is encoded as a JSON array element. For some use cases it is easier to consume a bunch of "bare" JSON objects - i.e. just write the individual JSON objects, possibly separated by a newline. As an option, of course. Proposal to add: ```java RestMulti.fromMultiData(multi).encodeAsArray(false)... ``` With `encodeAsArray(false)`, the produced JSON would look like this: ```json {"some": "value"} {"some": "value"} {"some": "value"} ``` `encodeAsArray(true)` or omitting it would use the current behavior and produce something like this: ```json [{"some": "value"}, {"some": "value"}, {"some": "value"} } ``` == Configure request-demand All implementations of `PublisherResponseHandler.AbstractMultiSubscriber` work with a hard-coded request-demand of `1`, which means that every emitted item is "produced"/"computed" serially / one-after-the-other. If the computation of individual items takes somewhat longer, possibly waiting for remote resources to reply, it makes sense to use a higher demand to produce multiple items concurrently. For example, if each item takes maybe 250 ms (requesting data from a remote source) to be produced, and 100 items are produced, it currently takes 25 seconds. With a higher concurrency it would take a fraction of that time. I.e. if the use case is known to be not CPU but (async) I/O bound, it _might_ be legit/feasible to use a high demand. Proposal to add: ``` RestMulti.fromMultiData(multi).withDemand( (long) 123 )... ``` Which would pass `123` as the demand for all call sites to `Subscription.request` in implementations of `PublisherResponseHandler.AbstractMultiSubscriber`.
1cfe6f5
to
0b1bf99
Compare
Status for workflow
|
Status for workflow
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely!
Adds two enhancements:
Produce multiple JSON objects
Currently,
PublisherResponseHandler.StreamingMultiSubscriber
produces a JSON array, where each emitted item is encoded as a JSON array element. For some use cases it is easier to consume a bunch of "bare" JSON objects - i.e. just write the individual JSON objects, possibly separated by a newline. As an option, of course.Proposal to add:
With
encodeAsArray(false)
, the produced JSON would look like this:encodeAsArray(true)
or omitting it would use the current behavior and produce something like this:Configure request-demand
All implementations of
PublisherResponseHandler.AbstractMultiSubscriber
work with a hard-coded request-demand of1
, which means that every emitted item is "produced"/"computed" serially / one-after-the-other. If the computation of individual items takes somewhat longer, possibly waiting for remote resources to reply, it makes sense to use a higher demand to produce multiple items concurrently.For example, if each item takes maybe 250 ms (requesting data from a remote source) to be produced, and 100 items are produced, it currently takes 25 seconds. With a higher concurrency it would take a fraction of that time. I.e. if the use case is known to be not CPU but (async) I/O bound, it might be legit/feasible to use a high demand.
Proposal to add:
Which would pass
123
as the demand for all call sites toSubscription.request
in implementations ofPublisherResponseHandler.AbstractMultiSubscriber
.