Last active
October 20, 2017 15:21
-
-
Save Ladas/ae5e723080108a9cc953fff249918692 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pod(uid) | |
| pod = {"kind" => "Pod", | |
| "apiVersion" => "v1", | |
| "metadata" => | |
| {"name" => "stress6-1-trz0g", | |
| "generateName" => "stress6-1-", | |
| "namespace" => "vcr-tests", | |
| "selfLink" => "/api/v1/namespaces/vcr-tests/pods/stress6-1-trz0g", | |
| "uid" => uid, | |
| "resourceVersion" => "1809029", | |
| "creationTimestamp" => "2017-10-19T13:11:50Z", | |
| "labels" => | |
| {"deployment" => "stress6-1", | |
| "deploymentconfig" => "stress6", | |
| "run" => "stress6"}, | |
| "annotations" => | |
| {"kubernetes.io/created-by" => | |
| "{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"vcr-tests\",\"name\":\"stress6-1\",\"uid\":\"0aab42e9-b4ce-11e7-8a08-001a4a162711\",\"apiVersion\":\"v1\",\"resourceVersion\":\"1809022\"}}\n", | |
| "openshift.io/deployment-config.latest-version" => "1", | |
| "openshift.io/deployment-config.name" => "stress6", | |
| "openshift.io/deployment.name" => "stress6-1", | |
| "openshift.io/scc" => "restricted"}, | |
| "ownerReferences" => | |
| [{"apiVersion" => "v1", | |
| "kind" => "ReplicationController", | |
| "name" => "stress6-1", | |
| "uid" => "0aab42e9-b4ce-11e7-8a08-001a4a162711", | |
| "controller" => true, | |
| "blockOwnerDeletion" => true}]}, | |
| "spec" => | |
| {"volumes" => | |
| [{"name" => "default-token-78s93", | |
| "secret" => {"secretName" => "default-token-78s93", "defaultMode" => 420}}], | |
| "containers" => | |
| [{"name" => "stress6", | |
| "image" => "docker.io/fsimonce/stress-test", | |
| "resources" => {}, | |
| "volumeMounts" => | |
| [{"name" => "default-token-78s93", | |
| "readOnly" => true, | |
| "mountPath" => "/var/run/secrets/kubernetes.io/serviceaccount"}], | |
| "terminationMessagePath" => "/dev/termination-log", | |
| "terminationMessagePolicy" => "File", | |
| "imagePullPolicy" => "Always", | |
| "securityContext" => | |
| {"capabilities" => | |
| {"drop" => ["KILL", "MKNOD", "SETGID", "SETUID", "SYS_CHROOT"]}, | |
| "privileged" => false, | |
| "seLinuxOptions" => {"level" => "s0:c11,c10"}, | |
| "runAsUser" => 1000130000}}], | |
| "restartPolicy" => "Always", | |
| "terminationGracePeriodSeconds" => 30, | |
| "dnsPolicy" => "ClusterFirst", | |
| "serviceAccountName" => "default", | |
| "serviceAccount" => "default", | |
| "nodeName" => "ladislav-ocp-3.6-infra01.10.35.49.18.nip.io", | |
| "securityContext" => | |
| {"seLinuxOptions" => {"level" => "s0:c11,c10"}, "fsGroup" => 1000130000}, | |
| "imagePullSecrets" => [{"name" => "default-dockercfg-l2ng9"}], | |
| "schedulerName" => "default-scheduler"}, | |
| "status" => | |
| {"phase" => "Pending", | |
| "conditions" => | |
| [{"type" => "Initialized", | |
| "status" => "True", | |
| "lastProbeTime" => nil, | |
| "lastTransitionTime" => "2017-10-19T13:11:50Z"}, | |
| {"type" => "Ready", | |
| "status" => "False", | |
| "lastProbeTime" => nil, | |
| "lastTransitionTime" => "2017-10-19T13:11:50Z", | |
| "reason" => "ContainersNotReady", | |
| "message" => "containers with unready status: [stress6]"}, | |
| {"type" => "PodScheduled", | |
| "status" => "True", | |
| "lastProbeTime" => nil, | |
| "lastTransitionTime" => "2017-10-19T13:11:50Z"}], | |
| "hostIP" => "10.35.49.18", | |
| "startTime" => "2017-10-19T13:11:50Z", | |
| "containerStatuses" => | |
| [{"name" => "stress6", | |
| "state" => {"waiting" => {"reason" => "ContainerCreating"}}, | |
| "lastState" => {}, | |
| "ready" => false, | |
| "restartCount" => 0, | |
| "image" => "docker.io/fsimonce/stress-test", | |
| "imageID" => ""}], | |
| "qosClass" => "BestEffort"}} | |
| end | |
| def update_with_jsonb_data(msg, save_options) | |
| connection = ActiveRecord::Base.connection | |
| jsonb_targets = save_options.delete(:jsonb_targets) | |
| jsonb_set_query = jsonb_targets.map do |target| | |
| target_data = target.second # Stored in format [target_class, target_data] | |
| "jsonb_data = jsonb_set(jsonb_data, '{#{target_data[:association]}___#{target_data[:manager_ref]}}', '#{target.to_json}')" | |
| #"jsonb_data = jsonb_data || ('{\"#{target_data[:association]}___#{target_data[:manager_ref]}\": #{target.to_json}}')" | |
| end.join(", ") | |
| options_set_query = save_options.map do |key, value| | |
| "#{connection.quote_column_name(key)} = #{connection.quote(value)}" | |
| end.join(", ") | |
| query = <<-SQL | |
| UPDATE miq_queue | |
| SET #{jsonb_set_query}, #{options_set_query} | |
| WHERE miq_queue.id = #{msg.id} | |
| SQL | |
| connection.execute(query) | |
| end | |
| (1..1000).each do |outer_counter| | |
| container_ems = ExtManagementSystem.last | |
| _, timings = Benchmark.realtime_block(:all) do | |
| 1000.times do |inner_counter| | |
| target = nil | |
| uid = "11bfe9da-b4cf-11e7-8a08-001a4a162711-#{(outer_counter * 1000) + inner_counter}" | |
| Benchmark.realtime_block(:make_target) do | |
| target = ManagerRefresh::Target.new( | |
| :manager => container_ems, | |
| :association => :container_groups, | |
| :manager_ref => uid, | |
| # :manager_ref => "11bfe9da-b4cf-11e7-8a08-001a4a162711", | |
| :options => { | |
| :payload => pod(uid), | |
| }.to_json, | |
| ) | |
| end | |
| Benchmark.realtime_block(:queue_refresh) do | |
| # EmsRefresh.queue_refresh([target, container_ems]) | |
| EmsRefresh.queue_refresh(target) | |
| end | |
| # msg = nil | |
| # Benchmark.realtime_block(:select_queue_item) do | |
| # msg = MiqQueue.select(MiqQueue.columns.map(&:name) - ['jsonb_data']).last | |
| # end | |
| # | |
| # Benchmark.realtime_block(:update_queue_item) do | |
| # update_with_jsonb_data( | |
| # msg, { | |
| # :jsonb_targets => [["ManagerRefresh::Target", target.dump]], | |
| # :updated_on => Time.now.utc | |
| # }) | |
| # end | |
| end | |
| end | |
| puts "#{outer_counter}. thousand Timings #{timings.inspect}" | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment