Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 81 lines (61 sloc) 1.63 KB
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
if ARGV.length < 1
print("usage: ./do-couch-view HOST [ OPT-NUM-OPS OPT-VIEW-NAME OPT-COMPARISON OPT-VIEW-CMD OPT-OUT-FILE ]\n" \
" ./do-couch-view 127.0.0.1 1000 last eq _view ~/tmp/view.out\n" \
" ./do-couch-view 127.0.0.1 1000 myView gte _set_view ~/tmp/view.out\n")
exit(-1)
end
host = ARGV[0]
base = "http://#{host}:5984"
n = (ARGV[1] || "1000").to_i
s = k = 0
v = ARGV[2] || "last"
comparison = ARGV[3]
cmd_params = ARGV[4] || "_view"
cmd = cmd_params.split(',')[0]
params = ""
if cmd_params.split(',')[1]
params = "&" + cmd_params.split(',')[1]
end
out = nil
if ARGV[5] # Optional output file path.
out = File.new(ARGV[5], 'w') # Allows users to compare to expected output.
end
class MyHTTP < Net::HTTP
def on_connect()
@socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
end
a = Time.now
MyHTTP.new(host, "5984").start do |http|
for x in 0..n
q = k.modulo(100).abs
extra = ""
extra = "&endkey=%22#{q}%22" if comparison == "eq"
path = "/default/_design/rampup-#{v}/#{cmd}/#{v}" \
"?startkey=%22#{q}%22&limit=10#{extra}&stale=ok#{params}"
req = Net::HTTP::Get.new(base + path)
req.add_field('Connection', 'keep-alive')
http.request(req) do |res|
body = res.read_body
if out
out.write(path)
out.write("\n")
out.write(body)
out.write("\n")
end
end
k = k + k.hash
end
end
b = Time.now
s = b - a
print "requests #{n}\n"
print "time #{s}\n"
print "req/sec #{n / s}\n"
if out
out.flush
out.close
end