-
Notifications
You must be signed in to change notification settings - Fork 392
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
Option to build longest dependency chain first (depth first mode?) #10435
Comments
From a first glance, it sounds like a reasonable request. Though I have no idea how a potential feature that addresses this problem might even look like. cc @snowleopard |
Implementation-wise, switching to a depth-first search ordering seems easy: replace a queue of jobs with a stack of jobs. However, it's unclear to me that this will actually speed-up this particular scenario. @Janno Could you give this implementation a try and check if it speeds things up for you? |
I can probably give it a try but I will need some guidance. So far I have only found |
For a prototype, it's probably easiest to replace this queue with a stack: dune/vendor/fiber/src/throttle.ml Lines 5 to 9 in b074bbe
|
Thanks for the pointer! It took me a while to set everything up but I can report some results now. The first result is that I have no idea what I am doing but I myself suspected as much when I went into this. So treat the rest with a big grain of salt. My test setup is dunetest.tar.gz: 9 slow files ( Without exchanging the queue for a stack, this project always builds the same way regardless of how many jobs are run in parallel: it will always build Output using Queue.t (dune master) and -j2
With the stack things are looking a little better but only marginally so: dune builds however many Output using Stack.t with -j2
Now this might look a whole lot better since only half the nested files are built in a wasteful way. Unfortunately the effect diminishes with greater parallelism. The gaps between This change could still help a bit in practice since the number of |
@Janno Cool :) How about trying random ordering instead? I'd expect it to do best on average. (Resource management is tricky and doing it optimally is hard. But randomness can often find a way!) |
I don't see how random ordering would be a good fit for this particular use case. The number of flat but slow files always outweighs the number of nested files that are ready to be worked on. I fear that if we select jobs randomly we will very likely delay the important files. At least with the stack we end up making guaranteed(?) gradual progress. |
I wonder if one could formulate some simple build ordering strategy that's guaranteed to be within a constant factor of the optimal one. (Also, do we have a definition of the optimal one?) |
Okay, I am 30 papers deep into a rabbit hole that's unfortunately not at all related to my field of research. So my understanding is still pretty limited. I'll try to summarize what I've learned. Finding a makespan-optimal schedule (i.e. a schedule that minimizes the maximal completion time--timestamp, not duration--of any job) for a set of tasks with dependencies ("precedences") even in the deterministic offline setting (i.e. all jobs are known beforehand as are their durations and dependencies) on If we ignore the fact that dune doesn't know how long tasks will take and that tasks can dynamically spawn new tasks (I think), dune seems to essentially already implement this algorithm. The list that Graham's algorithm presupposes is not fully materialized but it can be read off the trace of files being chosen. That laziness adds no potential for theoretical performance improvements as the theoretical framework already allows the list to be constructed based on all possible information, including the full list of tasks, dependencies, and task duration. This also implies that the choice between stack and queue or shortest paths and longest paths does not make a difference in terms of the approximation factor. Both choices admit scenarios in which the If we try to factor in the the added complexity of the exact scenario that dune faces it becomes much harder to find published results. There's is a bit of work on precedence scheduling in the stochastic scenario but I don't think we will find a reasonable family of probability distributions that affords us any benefit over simply not assuming anything. In the case of truely unknown task durations there is very little research and most of it takes the uncertainty farther in that they also assume the full task set and their dependencies are unknown and only revealed once earlier tasks finish. I could not find useful algorithmic results here. The takeaway for me is that we are unlikely to find a generic, (close-to) optimal algorithm that significantly improves on what is implemented right now in the worst case. Clearly, in practice and for my particular use case, preferring critical paths leads to favourable outcomes but counterexamples can be constructed that still produce the dreaded It also occurred to me that it would probably be very easy for dune to collect a bit of transient timing information somewhere based on previous (successful) builds. Tying that information purely to the file's path (i.e. not invalidating it when files change) would allow us to estimate the true cost of critical paths and thus allow us to favor truely critical paths over those that are merely long. I don't know how most of dune is implemented so maybe this information is not easy to gather or to exploit but it could be worth a shot. If this doesn't work, I would still go with the longest path criterion as an approximation. (Assuming that is actually implementable.) |
Desired Behavior
It seems dune currently schedules the easiest-to-get-to files first. I would like to have a depth first mode that assumes the longest chain is also the costliest chain and thus the first one to work on.
Desired Behavior
I work on a Coq project in which most proofs usually have dozens or hundreds of "flat" dependencies (files that can be build completely independently) and one very long, almost linear chain of more interesting dependencies. When building these proofs dune spends a lot of time build the trivial files and only then starts working on the long chain. In practice this can double the time it takes to get to the actual file since during the long chain all these smaller files could be built on idle cores.
The text was updated successfully, but these errors were encountered: