Skip to content

Instantly share code, notes, and snippets.

@cben
Last active November 27, 2017 10:49
Show Gist options
  • Select an option

  • Save cben/c858283bd4fcbaeec97ea0a5e5f046f9 to your computer and use it in GitHub Desktop.

Select an option

Save cben/c858283bd4fcbaeec97ea0a5e5f046f9 to your computer and use it in GitHub Desktop.
benchmarking manageiq tag mapping approaches for openshift

Everything timed on top of already refreshed inventory.
"save_inventory" column is total persisting time.

controlled_by_mapping counts: 16 Tag, 42 Tagging

One by one controls_tag? (but already improved from Fine)

https://github.com/ManageIQ/manageiq/tree/ec243f8f8350d6032c1dd58f0f51678411d09a6f without ManageIQ/manageiq-providers-kubernetes#162, ManageIQ/manageiq-providers-openshift#64

Classic refresh

no tags => creates tags & assigns them.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.4323 0.3938 2.7988
0.5493 0.3965 2.6255
0.3852 0.3848 2.3217

existing tags => finds tags & assigns them.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.039 0.3801 1.9341
0.0359 0.4319 1.9741
0.037 0.4963 2.4889

already tagged.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.0356 0.336 1.8912
0.0365 0.3451 1.9422
0.0383 0.3943 2.2026

Complex join

https://github.com/ManageIQ/manageiq/tree/49e4338f3af6f6c49c8c6ac1e913e1d72c5e6441, with the 2 kubernetes, openshift PRs

Classic refresh

no tags => creates tags & assigns them.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.3571 0.4436 3.1123
0.3855 0.4328 2.4918
0.3347 0.5528 2.7787

existing tags => finds tags & assigns them.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.035 0.4363 2.029
0.0379 0.5231 2.3232
0.0749 0.6137 2.799

already tagged.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.0625 0.5677 2.9167
0.0347 0.4224 2.2749
0.0336 0.4347 1.952

Graph refresh

no tags => creates tags & assigns them.

SaveCollection mapped_tags_to_resolve SaveCollection taggings_for_* save_inventory
0.3971 0.0448 1.0288
0.3431 0.0534 0.9572
0.3821 0.0542 1.1384

existing tags => finds tags & assigns them.

SaveCollection mapped_tags_to_resolve SaveCollection taggings_for_* save_inventory
0.033 0.0494 0.6589
0.0435 0.0537 0.691
0.0364 0.0553 0.7478

already tagged.

SaveCollection mapped_tags_to_resolve SaveCollection taggings_for_* save_inventory
0.0303 0.0531 0.6295
0.0404 0.0566 0.7386
0.0387 0.0532 0.6585

Prefix-based

https://github.com/ManageIQ/manageiq/tree/eb1000d96c89af450186ec9144250390ed3afeb0, with the 2 kubernetes, openshift PRs

Classic refresh

no tags => creates tags & assigns them.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.3932 0.3233 2.703
0.3779 0.3068 2.5221
0.3867 0.2923 2.2509

existing tags => finds tags & assigns them.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.0365 0.3289 2.0441
0.0366 0.3163 1.9654
0.0339 0.3091 1.918

already tagged.

SaveCollection mapped_tags_to_resolve retag_entity save_inventory
0.0341 0.2977 2.0042
0.0355 0.2782 2.0248
0.033 0.2878 1.9569

Graph refresh

no tags => creates tags & assigns them.

SaveCollection mapped_tags_to_resolve SaveCollection taggings_for_* save_inventory
0.467 0.0477 1.2678
0.3838 0.0471 1.0984
0.3855 0.0566 1.2029

existing tags => finds tags & assigns them.

SaveCollection mapped_tags_to_resolve SaveCollection taggings_for_* save_inventory
0.0384 0.0489 0.7033
0.0397 0.0498 0.7628
0.0397 0.0461 0.6895

already tagged.

SaveCollection mapped_tags_to_resolve SaveCollection taggings_for_* save_inventory
0.0407 0.0465 0.7001
0.0386 0.0498 0.7481
0.039 0.0552 0.7309
def map(label_name)
category = Classification.create_category!(name: Classification.sanitize_name("kubernetes::#{label_name}"), description: "Mapped #{label_name}", read_only: true, single_value: true)
ContainerLabelTagMapping.create!(label_name: label_name, tag: category.tag)
end
map("app")
map("name")
map("docker-registry")
pp ContainerLabelTagMapping.all.map {|m| [m.tag]}
#[[#<Tag:0x00560907ac9160 id: 132, name: "/managed/kubernetes::app">],
# [#<Tag:0x00560907ac1668 id: 146, name: "/managed/kubernetes::name">],
# [#<Tag:0x00560907ab1790 id: 147, name: "/managed/kubernetes::docker_registry">]]
# See all taggings
pp Tagging.where.not(taggable_type: 'RssFeed').collect {|tt| [tt.tag.name, tt.taggable_type, tt.taggable.name, tt.taggable_id] }
# Add 3 user-assigned tags to everything
ems.class.reflections.select { |name, reflection| reflection.macro == :has_many }.each { |name, reflection| [name, ems.send(name).each { |obj| obj.tag_add(['location/paris', 'department/engineering', 'environment/test'], ns: '/managed') if obj.respond_to?('tag_add')} ] }
p Tagging.where.not(taggable_type: 'RssFeed').count
#=> 689
# Refresh from VCR
# ================
# Based on https://gist.github.com/cben/cc5a30db507b13bfd57a3f045713fed2
# find a provider to sacrifice (better without much inventory, though should work anyway)
ems = ExtManagementSystem.last
$refresher = ems.refresher.new([ems])
require 'vcr'
VCR.configure {|c| c.hook_into :webmock; c.cassette_library_dir = '/home/bpaskinc/miq/grafresh'}
ActiveRecord::Base.logger.level = Logger::INFO # disable SQL query logging
EmsRefresh.debug_failures = true
def measure
_, timings = VCR.use_cassette('ose-16-31-50.yml', :match_requests_on => [:path,]) do
Benchmark.realtime_block(:ems_total_refresh) { $refresher.refresh }
end
taggings_sum = timings.select {|k,v| k.to_s.include?("taggings_for_")}.values.sum
timings["SaveCollection taggings_for_*"] = taggings_sum if taggings_sum > 0
timings.slice("SaveCollection mapped_tags_to_resolve", "SaveCollection taggings_for_*", :retag_entity, :save_inventory)
end
def measurements
table = []
3.times do
yield # setup
table << measure
end
table = table.map { |row| row.transform_values { |v| v.round(4) } } # less noise
puts table.tableize.gsub(/-\+-/, '-|-').gsub(/^/, '| ').chomp.gsub(/$/, ' |') # markdown table
end
def stages
puts "\n### no tags => creates tags & assigns them."
measurements do
#Tag.controlled_by_mapping.each {|t| t.classification.destroy}
ContainerLabelTagMapping.find_each {|m| m.tag.classification.entries.destroy_all } # Destroy all mapping-generated tags.
end
puts "\n### existing tags => finds tags & assigns them."
measurements do
#Tagging.joins(:tag).merge(Tag.controlled_by_mapping).delete_all
ContainerLabelTagMapping.find_each {|m| m.tag.classification.entries.map {|e| e.tag.taggings.delete_all } }
end
puts "\n### already tagged."
measurements {}
end
measure
puts "Everything timed on top of already refreshed inventory."
puts "controlled_by_mapping counts: #{Tag.controlled_by_mapping.count} Tag, #{Tagging.joins(:tag).merge(Tag.controlled_by_mapping).count} Tagging"
puts "\n## Classic refresh"
Settings.ems_refresh.openshift.inventory_object_refresh = false
stages
puts "\n## Graph refresh"
Settings.ems_refresh.openshift.inventory_object_refresh = true
stages
<<EOF
# Prefix-based
# Complex join
# One by one controls_tag? (but already improved from Fine)
EOF
container_limits 0
container_limit_items 0
container_nodes 1
persistent_volume_claims 1
computer_systems 1
computer_system_hardwares 1
computer_system_operating_systems 1
all_container_nodes 1
endpoints 2
authentications 2
persistent_volumes 2
container_builds 2
container_build_pods 2
container_quotas 3
container_image_registries 3
container_routes 6
container_replicators 11
container_quota_items 11
container_services 13
container_projects 13
all_container_projects 13
container_groups 22
containers 22
container_port_configs 22
security_contexts 22
container_service_port_configs 23
all_containers 25
all_container_groups 25
container_templates 28
container_images 50
all_container_images 50
container_volumes 51
container_env_vars 83
container_template_parameters 269
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment