Skip to content

Commit

Permalink
[miq_provision_virt_workflow.rb] Use VmOrTemplate#platform
Browse files Browse the repository at this point in the history
Very large performance improvement from this patch on large collections
of templates since it avoids preloading all together, reducing the
number of iterations over the VM collection, and the number of support
objects needing to be introduced (that would later need to be garbage
collected.

Benchmark
---------

**Before**

|     ms | queries | query (ms) |   rows |
|   ---: |    ---: |       ---: |   ---: |
|  27107 |      33 |     1958.5 | 243133 |
|  26803 |      33 |     1944.2 | 243133 |
|  27642 |      33 |     1965.5 | 243133 |

**After**

|     ms | queries | query (ms) |   rows |
|   ---: |    ---: |       ---: |   ---: |
|  14344 |      33 |     1759.6 | 243133 |
|  14631 |      33 |     1729.0 | 243133 |
|  13405 |      33 |     1752.3 | 243133 |
  • Loading branch information
NickLaMuro committed Jan 15, 2019
1 parent 871f2b8 commit 39b3e6e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/models/miq_provision_virt_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,13 @@ def tag_symbol
:vm_tags
end

VM_OR_TEMPLATE_EXTRA_COLS = %i(mem_cpu cpu_total_cores v_total_snapshots allocated_disk_storage).freeze
VM_OR_TEMPLATE_EXTRA_COLS = %i(
platform
mem_cpu
cpu_total_cores
v_total_snapshots
allocated_disk_storage
).freeze
def allowed_templates(options = {})
# Return pre-selected VM if we are called for cloning
if [:clone_to_vm, :clone_to_template].include?(request_type)
Expand Down Expand Up @@ -355,7 +361,6 @@ def allowed_templates(options = {})
end
end

MiqPreloader.preload(allowed_templates_list, %i(operating_system))
@_ems_allowed_templates_cache = {}
@allowed_templates_cache = allowed_templates_list.collect do |template|
create_hash_struct_from_vm_or_template(template, options)
Expand Down Expand Up @@ -1055,7 +1060,7 @@ def create_hash_struct_from_vm_or_template(vm_or_template, options)
:evm_object_class => :Vm}
data_hash[:cloud_tenant] = vm_or_template.cloud_tenant if vm_or_template.cloud_tenant_id
if vm_or_template.operating_system
data_hash[:operating_system] = MiqHashStruct.new(:product_name => vm_or_template.operating_system.product_name)
data_hash[:operating_system] = MiqHashStruct.new(:product_name => vm_or_template.operating_system_product_name)
end
if options[:include_datacenter] == true
data_hash[:datacenter_name] = vm_or_template.owning_blue_folder.try(:parent_datacenter).try(:name)
Expand Down

0 comments on commit 39b3e6e

Please sign in to comment.