61 lines
2.4 KiB
Markdown
61 lines
2.4 KiB
Markdown
# Job scheduling. Using Rust.
|
|
|
|
Benchmark of several job scheduling algorithms implemented in Rust.
|
|
|
|
|
|
## The problem
|
|
|
|
We have a list of independent tasks that we want to execute as fast as
|
|
possible. In order to achieve this, we want to run then in parallel. However,
|
|
those tasks have different execution times that can vary from several orders of
|
|
magnitude. Fortunately, it is possible to estimate the execution time of each
|
|
task before running it.
|
|
|
|
The goal is therefore to schedule the execution of the tasks on all available
|
|
threads in such a way that minimizes the total running time. This is known as
|
|
the [optimal job scheduling problem][ojs problem] and can often be seen as a
|
|
[partition problem][part problem], which is known to be
|
|
[NP-complete][NP-complete].
|
|
|
|
[ojs problem]: https://en.wikipedia.org/wiki/Optimal_job_scheduling
|
|
[part problem]: https://en.wikipedia.org/wiki/Partition_problem
|
|
[NP-complete]: https://en.wikipedia.org/wiki/NP-completeness
|
|
|
|
### Example
|
|
|
|
If we have 4 tasks tasks to execute. Three of then takes 1 second each to
|
|
execute and the last one takes 3 seconds. We have 2 processing units of equal
|
|
power.
|
|
|
|
If each processing unit starts by executing one of the 1s tasks, they will both
|
|
finis this job after one second. Then, one of those processing unit will
|
|
execute the remaining 1s task while the other will execute the 3s task. At the
|
|
end, one processing unit would have ran 2 seconds and the other one 4 seconds.
|
|
The total time is therefore 4 seconds.
|
|
|
|
Instead, we could start having one processing unit to execute the 3s task and
|
|
the other one execute the three 1s task. At the end, both processing units
|
|
would have ran 3 seconds. The total time is therefore 3 seconds.
|
|
|
|
The second job scheduling was clearly better than the first one, resulting in
|
|
zero idling processing unit and therefore the shortest total execution time.
|
|
|
|
|
|
## Goal
|
|
|
|
Talking about job scheduling algorithms and all the cool stuff you can use to
|
|
implement them in an efficient way is one thing. Actually implementing them and
|
|
gathering data on how it actually went in a real situation is another.
|
|
|
|
This project choses the later and therefore aims to implement several of those
|
|
algorithms in Rust and benchmark them. Let the battle begin.
|
|
|
|
|
|
## How to use
|
|
|
|
1. Install [Rust][rust] and [gnuplot][gnuplot].
|
|
2. Run `cargo bench`.
|
|
3. Look at the results in `./target/criterion/report/`.
|
|
|
|
[rust]: https://www.rust-lang.org/
|
|
[gnuplot]: http://www.gnuplot.info/
|