Skip to content
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

Load Balancing Algorithm doesn't consider weight of nodes #98

Closed
prostko opened this issue Oct 29, 2020 · 3 comments
Closed

Load Balancing Algorithm doesn't consider weight of nodes #98

prostko opened this issue Oct 29, 2020 · 3 comments

Comments

@prostko
Copy link

prostko commented Oct 29, 2020

It seems that this is the current algorithm used to assign specs to nodes:
Round Robin

  1. sorts the spec list by execution time (weight)
  2. iterates over the spec list and assigns each of the nodes the current spec by index

This can be optimized by:
Least Connections Algorithm

  1. sorting the spec list by execution time (weight)
  2. iterating over the spec list and for each of the specs:
  • Finding the current lightest node
  • assigning the current spec to lightest node
  • adding the weight of the current spec to the weight of the lightest node

This way the nodes will be more balanced.

@prostko
Copy link
Author

prostko commented Oct 29, 2020

Also, thanks a lot! Love the project!

More than happy to submit a PR if this is interesting

@ArturT
Copy link
Member

ArturT commented Oct 30, 2020

Hi @prostko

Sounds like an interesting idea.

If you would like to work on this you can take a look at
Knapsack::Distributors::ReportDistributor takes care of sorting test files with known time execution (test files in JSON report).
https://github.com/ArturT/knapsack/blob/387181ed7a459557770514c676771eff27dc3e1f/lib/knapsack/allocator.rb#L8
https://github.com/ArturT/knapsack/blob/387181ed7a459557770514c676771eff27dc3e1f/lib/knapsack/distributors/report_distributor.rb#L3

Knapsack::Distributors::LeftoverDistributor takes care of test files with unknown time execution (for instance someone added a new test file and it is not yet in JSON report - this file is called leftover).

List of test files for a given node index from ReportDistributor + LeftoverDistributor are passed to RSpec as allocator.stringify_node_tests
https://github.com/ArturT/knapsack/blob/387181ed7a459557770514c676771eff27dc3e1f/lib/knapsack/runners/rspec_runner.rb#L15 (it looks similar for other runners like cucumber, minitest, etc)

dynamic tests split

A bit similar idea to Least Connections Algorithm you can find in Knapsack Pro Queue Mode that will dynamically split tests between parallel nodes. This way you solve problems when nodes start at a different times or test files have random execution time.

You can check this article https://docs.knapsackpro.com/2020/how-to-speed-up-ruby-and-javascript-tests-with-ci-parallelisation

@ArturT
Copy link
Member

ArturT commented Oct 28, 2022

I'm closing this issue because #99 was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants