Comments (4)
Adding something like priority_hint
to the Future
trait seems pretty similar to the size_hint
method on Iterator
: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.size_hint
from futures-concurrency.
One idea I had was to add an additional trait, something like this:
trait SchedulingWeight {
fn scheduling_weight(&self) -> usize;
}
Then for tuples we'd have something like:
impl<A, B> SchedulingWeight for (A, B)
where
A: SchedulingWeight,
B: SchedulingWeight,
{
fn scheduling_weight(&self) -> usize {
self.0.scheduling_weight() + self.1.scheduling_weight()
}
}
In the implementation of Future
for (A, B)
, we could set it up so that if A::scheduling_weight()
returns 1 and B::scheduling_weight()
returns 2, then we poll B
twice as often as we poll A
.
There are some significant challenges with this approach. Mainly, most futures do not implement SchedulingWeight
(in fact, all futures do not since the trait does not exist 😃), so we don't have a good way of graceful degradation. We might be able to work around a lot of the issues, but I think we're likely to end up with another sandwich problem where you have a Future + SchedulingWeight
container that contains a Future
that contains a Future + SchedulingWeight
, and then we lose all the weighting information for the inner future.
So I think a more workable solution is to extend the future trait with a scheduling_weight
(or maybe scheduling_hint
or scheduling_weight_hint
or priority_hint
) method that has a default impl that returns 1. That way, by default we get the current behavior, but if futures want to provide more precise information they can override the method.
Also, if Rust gets impl specialization or refinement, that might open some other options up to us.
from futures-concurrency.
I'm re-visiting some of the outstanding issues on this repo, and I didn't get around to saying it last time: but I really like the idea of a scheduling_weight
method on future. this would allow us to solve the fairness issue in a transparent way for all futures combinators, in a way that would compose really nicely.
Maybe we should ACP that to get an experiment going?
from futures-concurrency.
I think an experiment seems like a good idea. I wonder if we could do it as a separate crate to prove the idea and then use that as evidence in an ACP?
from futures-concurrency.
Related Issues (20)
- Governance while yosh is out of office HOT 2
- Implement PinnedDrop for `impl RaceOk for Tuple` HOT 2
- Explain difference between https://github.com/rust-lang/futures-rs HOT 1
- Possibly unnecessary use of `Mutex` in `Merge` implementation? HOT 1
- Stream `merge` function calls `poll_next` again after returning `Poll::Ready(None)` HOT 7
- Sould futures in `Join` be dropped at completion of each? HOT 3
- Proposal: add `stream::Race` HOT 1
- Fix bounds on `impl {Chain,Zip} for tuple` HOT 1
- Add `try_join` and `race_ok` methods to `FutureExt`
- TryJoin2 polls completed futures HOT 5
- `tracing` can't track the execution duration of futures passed to `futures-concurrency`
- Where is `TryMerge` :-)? HOT 2
- Add a `StreamSet` API HOT 1
- How should I factor my specific problem, and more broadly, how should I handle `Result<!, E>`? HOT 2
- Using .join() on an empty Vec stalls HOT 2
- Add `PollState{,s}::set_consumed`
- Add a benchmark comparing task spawning vs in-line joining
- Fix docs
- Improve error handling `race_ok` variants HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from futures-concurrency.