Created
June 7, 2019 15:51
-
-
Save openscript/7fa898ad5902fa785067ba4919221cae 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
# see https://github.com/brianfrankcooper/YCSB/wiki/Running-a-Workload | |
# see https://github.com/brianfrankcooper/YCSB/wiki/Core-Properties | |
require 'csv' | |
require 'logger' | |
# test parameters | |
@recordcount = 10000 | |
@operationcount = 10000 | |
@threads = (1..1) # (from..to) | |
@target = (500..2500).step(100) | |
@cycles = 1 # cycles per target and thread combination | |
@workload = 'workloads/workloada' | |
# test environment | |
@workspace = ARGV[0] ? ARGV[0] : '.' | |
@ycsb_path = "#{@workspace}/bin/ycsb" | |
@other_parameters = "-s -P #{@workspace}/#{@workload}" | |
@database_type = 'redis' | |
@database_configuration = '-p "redis.host=10.0.2.148" -p "redis.port=6379" -p "redis.password=abcd"' | |
@static_test_parameters = "-p recordcount=#{@recordcount} -p operationcount=#{@operationcount}" | |
@output_file_path = "#{Dir.pwd}/raw-output.csv" | |
@output_file_parameter = "-p exportfile=#{@output_file_path}" | |
@result_file_path = "#{Dir.pwd}/result.csv" | |
@transposed_result_file_path = "#{Dir.pwd}/tresult.csv" | |
# script environment | |
@logger = Logger.new(STDOUT) | |
@logger.level = Logger::INFO | |
@parsed_output = nil | |
def execute command | |
@logger.debug "Running #{command}" | |
status = system command | |
unless status | |
@logger.fatal "Execution of #{command} failed." | |
end | |
status | |
end | |
def load_data_set | |
unless execute "#{@ycsb_path} load #{@database_type} #{@other_parameters} #{@database_configuration} #{@static_test_parameters}" | |
@logger.fatal 'Couldn\'t load test data.' | |
end | |
end | |
def execute_workload | |
@threads.each do |thread_count| | |
@target.each do |target_count| | |
@cycles.times do |cycle| | |
@logger.info "Running cycle #{cycle + 1} with #{thread_count} threads and #{target_count} target" | |
unless execute "#{@ycsb_path} run #{@database_type} #{@other_parameters} #{@database_configuration} #{@output_file_parameter} #{@static_test_parameters} -threads #{thread_count} -target #{target_count}" | |
@logger.fatal 'Workload execution failed.' | |
next | |
end | |
parse_output | |
end | |
end | |
end | |
@logger.debug "Cycles completed" | |
end | |
def parse_output | |
@logger.debug 'Parse output from last run and add it to run output' | |
last_output = CSV.read(@output_file_path) | |
if @parsed_output | |
@logger.debug 'Add new results' | |
@parsed_output.map!.with_index do |item,index| | |
item << last_output[index].last | |
item | |
end | |
else | |
@logger.debug 'First results' | |
@parsed_output = last_output | |
end | |
end | |
def save_results | |
@logger.debug 'Save results' | |
if @parsed_output | |
File.write(@result_file_path, @parsed_output.map { |r| r.join(',') }.join("\n")) | |
File.write(@transposed_result_file_path, @parsed_output.transpose.map { |r| r.join(',') }.join("\n")) | |
else | |
@logger.fatal 'Nothing to save' | |
end | |
end | |
load_data_set | |
execute_workload | |
save_results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment