-
-
Save carbonin/1c5ac63ce304e2727e15 to your computer and use it in GitHub Desktop.
This file contains 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
require 'pg' | |
require 'benchmark' | |
DATA = "a" * 100 | |
rows = ARGV[0].to_i | |
rep_type = ARGV[1] | |
def time_bdr(target) | |
local_conn = PGconn.connect(:dbname => 'vmdb_production') | |
remote_conn = PGconn.connect(:host => target, :dbname => 'vmdb_production', :password => 'smartvm') | |
remote_conn.exec("select bdr.bdr_apply_resume()") | |
Benchmark.realtime do | |
loop do | |
res = local_conn.exec("select pg_xlog_location_diff(pg_current_xlog_location(), flush_location) as lag_bytes from pg_stat_replication").first | |
break if res && res['lag_bytes'].to_i == 0 | |
sleep(0.2) | |
end | |
end | |
ensure | |
local_conn.close | |
remote_conn.close | |
end | |
def pause_bdr_remote(target) | |
conn = PGconn.connect(:host => target, :dbname => 'vmdb_production', :password => 'smartvm') | |
conn.exec("select bdr.bdr_apply_pause()") | |
sleep(1) until conn.exec("select bdr.bdr_apply_is_paused() as paused").first['paused'] == 't' | |
ensure | |
conn.close | |
end | |
def time_rubyrep | |
conn = PGconn.connect(:dbname => 'vmdb_production') | |
pid = Process.spawn("bin/rake evm:dbsync:replicate", :chdir => "/var/www/miq/vmdb") | |
Benchmark.realtime do | |
loop do | |
backlog = conn.exec("select count(id) from rr1_pending_changes where change_table = 'test'").first['count'].to_i | |
break if backlog == 0 | |
sleep(0.2) | |
end | |
end | |
ensure | |
begin | |
Process.kill("INT", pid) | |
rescue Errno::ESRCH | |
end | |
end | |
def insert_rows(rows) | |
conn = PGconn.connect(:dbname => 'vmdb_production') | |
Benchmark.realtime do | |
rows.times do |i| | |
conn.exec("insert into test (id, data) values (#{i}, '#{DATA}')") | |
end | |
end | |
ensure | |
conn.close | |
end | |
rep_time = 0 | |
insert_time = 0 | |
case rep_type | |
when "rubyrep" | |
insert_time = insert_rows(rows) | |
rep_time = time_rubyrep | |
when "bdr" | |
rep_target = ARGV[2] | |
pause_bdr_remote(rep_target) | |
insert_time = insert_rows(rows) | |
rep_time = time_bdr(rep_target) | |
end | |
puts "#{rep_type}:\n insert took: #{insert_time.round(2)}s\n replicated #{rows} rows in #{rep_time.round(2)}s" |
This file contains 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
rubyrep: | |
1,000 rows: | |
insert: 0.2 | |
replicate: 7.42 | |
1,000 rows: | |
insert: 0.2 | |
replicate: 7.22 | |
10,000 rows: | |
insert: 1.87 | |
replicate: 15.94 | |
10,000 rows: | |
insert: 1.77 | |
replicate: 15.18 | |
100,000 rows: | |
insert: 19.77 | |
replicate: 100.97 | |
100,000 rows: | |
insert: 20.07 | |
replicate: 104.28 | |
1,000,000 rows: | |
insert: 197.47 | |
replicate: 952.35 | |
1,000,000 rows: | |
insert: 191.25 | |
replicate: 1005.44 | |
bdr: | |
1,000 rows: | |
insert: 0.17 | |
replicate: 2.01 | |
1,000 rows: | |
insert: 0.17 | |
replicate: 2.01 | |
10,000 rows: | |
insert: 1.71 | |
replicate: 1.61 | |
10,000 rows: | |
insert: 1.73 | |
replicate: 1.61 | |
100,000 rows: | |
insert: 16.58 | |
replicate: 3.61 | |
100,000 rows: | |
insert: 18.37 | |
replicate: 3.81 | |
1,000,000 rows: | |
insert: 162.86 | |
replicate: 26.11 | |
1,000,000 rows: | |
insert: 167.84 | |
replicate: 26.08 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment