ms | bytes | objects | queries | query (ms) | rows | comments |
---|---|---|---|---|---|---|
290.5 | 21,380,122* | 225,801 | 2 | 28.0 | 1,598 | before |
244.9 | 18,410,393* | 188,824 | 1 | 4.6 | after |
* Memory usage does not reflect 262 freed objects. (for both of them)
create index i_hosts_i_h on hosts(name, id); | |
create index i_hosts_h_i on hosts(id, name); | |
explain analyze verbose | |
SELECT "vms".id FROM "vms" left join "hosts" on "hosts"."id" = "vms"."host_id" ORDER BY "hosts"."name" | |
; | |
QUERY PLAN | |
----------------------------------------------------------------------------------------------------------------------------- | |
Sort (cost=440.76..448.26 rows=3000 width=36) (actual time=30.724..30.884 rows=3000 loops=1) | |
Output: vms.id, hosts.name |
require 'benchmark/ips' | |
def eval_eval_true | |
name = "Benchmark" | |
eval("defined?(#{name}) && #{name}.class").to_s.eql?('Module') | |
end | |
def eval_eval_false | |
name = "XABCDE" | |
eval("defined?(#{name}) && #{name}.class").to_s.eql?('Module') |
ms | bytes | objects | queries | query (ms) | rows | comments |
---|---|---|---|---|---|---|
290.5 | 21,380,122* | 225,801 | 2 | 28.0 | 1,598 | before |
244.9 | 18,410,393* | 188,824 | 1 | 4.6 | after |
* Memory usage does not reflect 262 freed objects. (for both of them)
#!/usr/bin/env ruby | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do |
#!/usr/bin/env ruby | |
require 'thread' | |
COLLECTOR_COUNT = 2 # define to run in separate threads. comment to run inline | |
class Db | |
def initialize | |
@mutex = Mutex.new | |
@data = {} | |
end | |
def []=(n, v) ; @mutex.synchronize { @data[n] = v } ; end |
<html> | |
<head><style> | |
table {border-collapse:collapse;} | |
table, td, th { border:1px solid black; } | |
.f0, a.f0 { color: #999; } | |
.f1, a.f1 { color: #ccc; } | |
</style> | |
</head> | |
<body> | |
<h2>!</h2> |
def reload_models | |
[Vm, Host, Storage].each { |m| m.update_all(:last_perf_capture_on => 50.minutes.ago) } # <== still tweaking | |
[MiqTask, MiqQueue, Metric, MetricRollup, VimPerformanceState].each { |m| m.truncate} | |
ActiveRecord::Base.connection.execute("vacuum full") | |
Module.clear_all_cache_with_timeout | |
[[MiqProductFeature, :@feature_cache], [MiqProductFeature, :@obj_cache], [BottleneckEvent, :@event_definitions], | |
[Tenant, :@root_tenant]].each { |i, ivar| i.instance_variable_set(ivar, nil) } | |
MiqServer.my_server ; MiqServer.my_zone | |
[ExtManagementSystem, Host, EmsCluster, Tagging, Tag, HostStorage, Storage, Vm, MiqRegion, MiqTask, Relationship, Disk, | |
Endpoint, Authentication, ServerRole, MiqWorker, MiqQueue, MetricRollup, BottleneckEvent].each { |m| m.first } |
gem | ||
---|---|---|
Json oj | 40.4 i/s | |
MessagePack | 38.3 i/s | same |
binary json | 22.0 i/s | 1.84x slower |
Json yajl | 19.0 i/s | 2.13x slower |
ruby json | 15.6 i/s | 2.59x slower |
ruby marshal | 13.9 i/s | 2.90x slower |
ruby yaml | 0.4 i/s | 111.99x slower |
Yaml Psych | 0.4 i/s | 112.09x slower |
Looking at the difference between using ActiveSupport::Notification
, and rolling our own metrics counters.
When logging, Notifications are 66% slower than manually adding the metrics code. The metrics code is actually 50% slower when not logging the results (no subscriber). Having no subscriber does speed up performance for all the cases.
The difference for timing for payload is probably due to allocations. Having a fixed payload ended up being equivalent to the no payload case. This is a reminder for us to pay attention to what we pass in the payload.
note: in the tests, we are setting a different variable @x
than the guard clause @x2
.
I tested a terciary ?:
vs the guard clause return if defined?()
and they were about the same for pass and fail case
test | int i/s | slower | text i/s | slower |
---|---|---|---|---|
eq2 | 6,315,053.7 i/s | same | 6,323,409.7 i/s | base |
neq2 | 6,281,137.2 i/s | same | 3,707,761.0 i/s | 1.71x |
eq | 5,978,924.2 i/s | same | 4,572,438.8 i/s | 1.38x |
include | 4,368,299.8 i/s | 1.45x | 4,349,531.4 i/s | 1.45x |
neq | 4,194,756.5 i/s | 1.51x | 4,170,358.7 i/s | 1.52x |