-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsperf_fiber.cr
178 lines (165 loc) · 4.73 KB
/
insperf_fiber.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/ruby
# #######################################################################
#
# Author: Brian Hood
# Name: Insert performance test with Crystal driver
# Codename: Dagobert I
# Description:
#
#
#
# #######################################################################
require "./src/monetdb"
require "./src/monetdb_data"
require "./src/tools"
require "colorize"
require "option_parser"
appname = "insperf_fiber"
host = "127.0.0.1"
port = 50000
username = "monetdb"
password = "monetdb"
db = "test"
schema = "myschema"
insloop = 10_000
splitnum = 2
displayinterval = 1000
timeout = 10
updaterands = 1
autocommit = false
deleterecordsall = false
def print_stamp
puts "Author: Brian Hood"
puts "Homepage: https://github.com/puppetpies/crystal-monetdb-libmapi\n"
puts "Description: \n\nCrystal bindings for MonetDB Testing Suite"
end
mero = MonetDB::ClientJSON.new
oparse = OptionParser.parse! do |parser|
parser.banner = "Usage: #{appname} [options]"
parser.on("-h 127.0.0.1", "--HOST=127.0.0.1", "\tIP / DNS Name") { |h|
mero.host = h
}
parser.on("-P 50000", "--PORT=50000", "\tTCP Port") { |f|
mero.port = f.to_i
}
parser.on("-u monetdb", "-USERNAME=monetdb", "\tUsername") { |f|
mero.username = f
}
parser.on("-p monetdb", "-PASSWORD=monetdb", "\tPassword") { |f|
mero.password = f
}
parser.on("-d database", "-DB=test", "\tDatabase") { |f|
mero.db = f
db = f
}
parser.on("-s schema", "-SCHEMA=schema", "\tSchema") { |f|
mero.schema = f
schema = f
}
parser.on("-a true", "--AUTOCOMMIT=true", "Enabled / Disable Autocommit") { |a|
if a == "true"
autocommit = true
else
autocommit = false
end
}
parser.on("-l ITERATIONS", "-LOOP=3000", "\tINSERT Iterations") { |f|
insloop = f.to_i
}
parser.on("-w SPLITWORK", "-SPLITWORK=5", "\tNumber of Fibers to split work interations into") { |s|
splitnum = s.to_i
}
parser.on("-i INTERVAL", "-INTERVAL=250", "\tDisplay Interval") { |d|
displayinterval = d.to_i
}
parser.on("-H", "--help", "\tDisplay options") {
print_stamp
puts parser
exit
}
end
oparse.parse!
mero.host ||= host
mero.port ||= port
mero.username ||= username
mero.password ||= password
mero.db ||= db
mero.schema ||= schema
puts ">> Server Information".colorize(:red)
puts "\n"
puts " > Merovingian Server: #{mero.host}".colorize(:blue)
puts " > Port: #{mero.port}".colorize(:blue)
puts " > Username: #{mero.username}".colorize(:blue)
puts " > Schema: #{mero.schema}".colorize(:blue)
puts " -> DB: #{mero.db}".colorize(:green)
mero.connect # Connect to a MServer5
mero.timeout(timeout)
isc = mero.is_connected?
puts " > Is Connected?: #{isc}".colorize(:blue)
ping = mero.ping?
puts " > Ping?: #{ping}".colorize(:blue)
uri = mero.get_uri
puts " > Merovingian URI: #{uri}".colorize(:blue)
puts " > Autocommit: #{autocommit}".colorize(:blue)
p mero
puts "\n>> Insert Test".colorize(:red)
if isc == false
abort ConnectionError.new "Not connected make sure the MServer is started and see ./insperf -h for details"
end
puts "\n>> Create Table Test Empty Table".colorize(:red)
sql = "CREATE TABLE \"#{db}\".table2 ( id int, thread int, firstname char(50), lastname char(50), age int);"
puts sql.colorize(:green)
hdl = mero.query(sql)
hdl = mero.commit
puts " - INSERT iterations: #{insloop}".colorize(:yellow)
firstnames = ["Edward", "Henry", "Robert", "Michael", "Dave", "Joe", "Kev"]
lastnames = ["Smith", "Jones", "Warbutton", "Blake", "Ward", "Johnston", "Abbot"]
c = 0
mero.setAutocommit(autocommit)
dur = Timers.new
dur.start
tm = Timers.new
tm.start
m = 0_u32
m_res = 0
worksplit = insloop / splitnum
puts "Worksplit: #{worksplit}"
puts "Insloop: #{insloop}"
puts "Split num: #{splitnum}"
splitnum.times { |x|
spawn do
puts "Swarm thread #{x}..."
worksplit.times { |n|
print "t: #{x} Query number: #{n} " if c == displayinterval
sql = "INSERT INTO \"#{db}\".table2 VALUES (#{n}, #{x}, '#{firstnames[rand(firstnames.size)]}', '#{lastnames[rand(lastnames.size)]}', #{rand(80)});"
hdl = mero.query(sql)
puts "SQL: #{sql}".colorize(:green) if c == displayinterval
if c == displayinterval
c = 0
tm.stop
puts tm.stats
tm.start
end
c += 1
m += 1
}
end
}
Fiber.yield
mero.commit
results_json = mero.query_json("SELECT count(*) as num FROM \"#{db}\".table2;")
hash_results = mero.json_to_hash(results_json)
puts "Record Count: ".colorize(:cyan)
hash_results.each { |x, n| puts n["num"]; m_res = n["num"] }
m_res_int = m_res.to_s.to_i
if m == m_res_int
puts "SUCCESS - Record count matches"
else
puts "FAIL - Actual records in table is different to records inserted ?"
end
puts "Total time:"
dur.stop
puts dur.stats
mero.query("DELETE FROM \"#{db}\".table2;")
mero.commit
mero.disconnect