-
Notifications
You must be signed in to change notification settings - Fork 897
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
[V2V] Modify active_tasks so that it always reloads #18860
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
class InfraConversionThrottler | ||
def self.start_conversions | ||
pending_conversion_jobs.each do |ems, jobs| | ||
running = ems.conversion_hosts.inject(0) { |sum, ch| sum + ch.active_tasks.size } | ||
running = ems.conversion_hosts.inject(0) { |sum, ch| sum + ch.active_tasks.count } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like a terrible N+1 (query in a loop is bad) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @kbrock There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there will be less than 20 conversion hosts. I did come up with a single query for this, but since it is not in the primary loop, that can hold off for another day. This is only called 1 time per ems and is a lower concern There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it may be tricky treating all conversion_hosts the same. I'll try and think of a way, but adding together encapsulating this and putting it into ems may at least make this method look good. |
||
$log&.debug("There are currently #{running} conversion hosts running.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why $log.debug { "There are currently #{running} conversion hosts running." } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, please remove this from the PR |
||
slots = (ems.miq_custom_get('Max Transformation Runners') || Settings.transformation.limits.max_concurrent_tasks_per_ems).to_i - running | ||
$log&.debug("The maximum number of concurrent tasks for the EMS is: #{slots}.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we remove this from the PR as well? |
||
jobs.each do |job| | ||
eligible_hosts = ems.conversion_hosts.select(&:eligible?).sort_by { |ch| ch.active_tasks.size } | ||
eligible_hosts = ems.conversion_hosts.select(&:eligible?).sort_by { |ch| ch.active_tasks.count } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a big fan of bringing back every conversion host to then select out the eligible ones. would like to find a way to get |
||
|
||
if eligible_hosts.size > 0 | ||
$log&.debug("The following conversion hosts are currently eligible: " + eligible_hosts.map(&:name).join(', ')) | ||
end | ||
|
||
break if slots <= 0 || eligible_hosts.empty? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again not you but, if there are no slots, do we even need to do this jobs.each - what will that buy us? |
||
job.migration_task.update_attributes!(:conversion_host => eligible_hosts.first) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is not you but... do we really need to bring back every eligible host? if we could get it into the query, could we just bring back the top host and vm and pick one of those? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. punting on this idea - looks like it may make sense to just cache the conversion hosts |
||
job.queue_signal(:start) | ||
_log.info("Pending InfraConversionJob: id=#{job.id} signaled to start") | ||
slots -= 1 | ||
|
||
$log&.debug("The current number of available tasks is: #{slots}.") | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please introduce
total_tasks
and reference that here.that way we can preload this value in this query and not cause an N+1
I understand that you don't want to have a cached value from more than 10 seconds ago, but caching it within a single query / second seems prudent and non-wasteful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, of note, this count is checked within a loop that also runs counts.
so a separate count here doesn't make sense.
(also using size and prefetching all active_tasks isn't much better)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consensus: this is bad and should be changed
BUT
not today
==> Keep it with
count