How can I perform flatMap using multiple threads in Reactor?
up vote
1
down vote
favorite
I have tried running a flatMap on a Flux range followed by subscribeOn and it seems all operations run on the same thread. Is this normal?
Flux.range(0, 1000000).log().flatMap{ it + 1 }.subscribeOn(Schedulers.parallel()).subscribe()
multithreading kotlin project-reactor
add a comment |
up vote
1
down vote
favorite
I have tried running a flatMap on a Flux range followed by subscribeOn and it seems all operations run on the same thread. Is this normal?
Flux.range(0, 1000000).log().flatMap{ it + 1 }.subscribeOn(Schedulers.parallel()).subscribe()
multithreading kotlin project-reactor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have tried running a flatMap on a Flux range followed by subscribeOn and it seems all operations run on the same thread. Is this normal?
Flux.range(0, 1000000).log().flatMap{ it + 1 }.subscribeOn(Schedulers.parallel()).subscribe()
multithreading kotlin project-reactor
I have tried running a flatMap on a Flux range followed by subscribeOn and it seems all operations run on the same thread. Is this normal?
Flux.range(0, 1000000).log().flatMap{ it + 1 }.subscribeOn(Schedulers.parallel()).subscribe()
multithreading kotlin project-reactor
multithreading kotlin project-reactor
edited Nov 21 at 10:25
honk
4,740114149
4,740114149
asked Nov 21 at 10:04
Andrew
4851919
4851919
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
You can create a ParallelFlux as follows:
Flux.range(0, 100000).parallel(2).runOn(Schedulers.parallel()).log().map{ it + 1 }.subscribe()
^^^^^^^^^^^ ^^^^^^use runOn ^^^^^^^^^^^
So flatMap doesn't break your streams into sub-streams that are processed in parallel? This is how the method was documented and thought only subscribeOn is necessary.
– Andrew
Nov 21 at 14:21
flatmapwill only parallelize if you create a new Observable(Flux, Mono) inside the block. In your example withit +1the operatorflatMapwill not compile and you should usemap. I just updated my answer. See stackoverflow.com/questions/43269275/…
– Rene
Nov 22 at 10:39
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You can create a ParallelFlux as follows:
Flux.range(0, 100000).parallel(2).runOn(Schedulers.parallel()).log().map{ it + 1 }.subscribe()
^^^^^^^^^^^ ^^^^^^use runOn ^^^^^^^^^^^
So flatMap doesn't break your streams into sub-streams that are processed in parallel? This is how the method was documented and thought only subscribeOn is necessary.
– Andrew
Nov 21 at 14:21
flatmapwill only parallelize if you create a new Observable(Flux, Mono) inside the block. In your example withit +1the operatorflatMapwill not compile and you should usemap. I just updated my answer. See stackoverflow.com/questions/43269275/…
– Rene
Nov 22 at 10:39
add a comment |
up vote
3
down vote
accepted
You can create a ParallelFlux as follows:
Flux.range(0, 100000).parallel(2).runOn(Schedulers.parallel()).log().map{ it + 1 }.subscribe()
^^^^^^^^^^^ ^^^^^^use runOn ^^^^^^^^^^^
So flatMap doesn't break your streams into sub-streams that are processed in parallel? This is how the method was documented and thought only subscribeOn is necessary.
– Andrew
Nov 21 at 14:21
flatmapwill only parallelize if you create a new Observable(Flux, Mono) inside the block. In your example withit +1the operatorflatMapwill not compile and you should usemap. I just updated my answer. See stackoverflow.com/questions/43269275/…
– Rene
Nov 22 at 10:39
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You can create a ParallelFlux as follows:
Flux.range(0, 100000).parallel(2).runOn(Schedulers.parallel()).log().map{ it + 1 }.subscribe()
^^^^^^^^^^^ ^^^^^^use runOn ^^^^^^^^^^^
You can create a ParallelFlux as follows:
Flux.range(0, 100000).parallel(2).runOn(Schedulers.parallel()).log().map{ it + 1 }.subscribe()
^^^^^^^^^^^ ^^^^^^use runOn ^^^^^^^^^^^
edited Nov 22 at 10:36
answered Nov 21 at 13:13
Rene
1,33115
1,33115
So flatMap doesn't break your streams into sub-streams that are processed in parallel? This is how the method was documented and thought only subscribeOn is necessary.
– Andrew
Nov 21 at 14:21
flatmapwill only parallelize if you create a new Observable(Flux, Mono) inside the block. In your example withit +1the operatorflatMapwill not compile and you should usemap. I just updated my answer. See stackoverflow.com/questions/43269275/…
– Rene
Nov 22 at 10:39
add a comment |
So flatMap doesn't break your streams into sub-streams that are processed in parallel? This is how the method was documented and thought only subscribeOn is necessary.
– Andrew
Nov 21 at 14:21
flatmapwill only parallelize if you create a new Observable(Flux, Mono) inside the block. In your example withit +1the operatorflatMapwill not compile and you should usemap. I just updated my answer. See stackoverflow.com/questions/43269275/…
– Rene
Nov 22 at 10:39
So flatMap doesn't break your streams into sub-streams that are processed in parallel? This is how the method was documented and thought only subscribeOn is necessary.
– Andrew
Nov 21 at 14:21
So flatMap doesn't break your streams into sub-streams that are processed in parallel? This is how the method was documented and thought only subscribeOn is necessary.
– Andrew
Nov 21 at 14:21
flatmap will only parallelize if you create a new Observable(Flux, Mono) inside the block. In your example with it +1 the operator flatMap will not compile and you should use map. I just updated my answer. See stackoverflow.com/questions/43269275/…– Rene
Nov 22 at 10:39
flatmap will only parallelize if you create a new Observable(Flux, Mono) inside the block. In your example with it +1 the operator flatMap will not compile and you should use map. I just updated my answer. See stackoverflow.com/questions/43269275/…– Rene
Nov 22 at 10:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409567%2fhow-can-i-perform-flatmap-using-multiple-threads-in-reactor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown