-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix #1177 Operators to capture last visible Scheduler and go back to it #1644
Conversation
cc @vy |
Codecov Report
@@ Coverage Diff @@
## master #1644 +/- ##
===========================================
+ Coverage 81.87% 84.27% +2.4%
- Complexity 3794 3939 +145
===========================================
Files 362 363 +1
Lines 30037 30070 +33
Branches 5592 5592
===========================================
+ Hits 24592 25342 +750
+ Misses 3899 3095 -804
- Partials 1546 1633 +87
Continue to review full report at Codecov.
|
Great work @simonbasle! Thanks so much for taking time to work on the issue! |
6973b12
to
a886878
Compare
I'm not too sure about the current form for this and we will surely evaluate it further in the current 3.3 cycle. Being explicit on the scheduler switch is also useful. Loom would provide us a better option obviously here but I'd love to see the current use case for this too now that can't be achieved with subscribeOn+publishOn. |
@smaldini, the usecase where |
There are two scenarios:
Keep in mind that
You don't need to, really.
You shouldn't care. The only thing you care is the thread starvation (caused by either IO or CPU-heavy tasks), but there is a common consumer's rule - if you need to perform some heavy operation, explicitly move it to a dedicated scheduler. |
@bsideup Thanks for taking time to check the issue.
How would you use Let me explain the situation using a concrete example:
Here the last step is not possible since Does this make more sense? Is my reasoning incorrect? |
Why would you "occupy" the thread if the only next thing you will do is a non-blocking, lightweight operation? Reactive programming abstracts the threading, and almost the only reason you need to care about the thread is because of the blocking I/O and heavy computations. Consider the following example: doSomethingInDB().flatMap(user -> fetchFriends(user))
Another example: doSomethingInDB().publishOn(blockingFriendlyScheduler).map(user -> fetchFriendsSync(user)) Here we know that |
Consider the following: |
I would say this code smells. The blocking calls should not be made without a strict control of the schedulers, and here you implicitly inherit the dedicated scheduler. |
I think this is a pretty reasonable case, even though it conflicts with your sense of good smell. Now replace |
Well, this is not my personal opinion. Running blocking operations on non-blocking threads is a dangerous, performance critical mistake. This is why we created BlockHound which helps detecting such calls. Every blocking call should be explicitly redirected to a dedicated scheduler.
Sorry, I still don't see why we need to return to the caller scheduler here.
This is not library's concern, really. As long as library's threads are not blocked, we're good. You can have tens of schedulers but the CPUs count will remain static, and it makes little to no sense to move the non-blocking lightweight operation to another pool which will run on the same CPU |
Hi, I just stumbled upon this usecase and thought about this ticket. I am writing a library which we intend to use in both spring-mvc and spring-webflux environment. I'm not sure after auth logic, whether the control should go back to |
It shouldn't. Spring Security stores the auth info in the context, not thread. |
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.
For now we have by design work-stealing everywhere and blocking paths are exceptional, however coming back to original thread. To reevaluate with Loom - Kotlin Coroutine integration ?
No description provided.