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

Sorting Algorithm: round robin to least connections #99

Conversation

prostko
Copy link

@prostko prostko commented Nov 1, 2020

references #98

Changes the Round Robin approach to a Least Connections approach.

  • All internal and external APIs should be unaffected.
  • No changes were made to specs without recorded benchmarks in Knapsack Report

Changes:

  • replaces some .sort.reverses with a sort_by { |x| -x } for readability and terseness
  • adds :weight key to default nodes
  • some specs needed changes for the new assignment of the algorithm
  • added some specs to ensure that the assignment is most optimal

@prostko prostko changed the title Sorting Aglorithm: round robin to least connections Sorting Algorithm: round robin to least connections Nov 1, 2020
@prostko
Copy link
Author

prostko commented Nov 2, 2020

TODO: remove > ruby 1.9.3 features

@ArturT ArturT merged commit b6a68ee into KnapsackPro:master Jun 23, 2021
end

def sorted_report_with_existing_tests
@sorted_report_with_existing_tests ||= sorted_report.select { |test_path, time| all_tests.include?(test_path) }
end

def total_time_execution
@total_time_execution ||= sorted_report_with_existing_tests.map(&:last).reduce(0, :+).to_f
@total_time_execution ||= sorted_report_with_existing_tests.sum { |_test_path, time| time }.to_f
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this line because sum method in not available in Ruby <= 2.3 and it was breaking CI build.

Here is the fix 0be9583

y[1] <=> x[1]
end
node_tests.map do |node|
node[:test_files_with_time].sort_by! { |file_name, _time| -file_name }
Copy link
Member

@ArturT ArturT Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will keep reverse! 96476a5 because sorting file_name string with - char does not work in Ruby 2.2 https://github.com/KnapsackPro/knapsack/runs/2896841914?check_suite_focus=true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using reverse! should not have a big impact on performance and it's more readable than using - char.

https://stackoverflow.com/questions/2642182/how-to-sort-an-array-in-descending-order-in-ruby

@ArturT
Copy link
Member

ArturT commented Jun 23, 2021

Thanks @prostko for the PR.

I've released knapsack 3.1.0 version.

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

Successfully merging this pull request may close these issues.

None yet

2 participants