Navigation Menu

Skip to content

Commit

Permalink
Add feature that verify cache hit rate. (#9)
Browse files Browse the repository at this point in the history
Patch by komainu8. Thanks!!!
  • Loading branch information
komainu8 authored and kou committed Apr 21, 2017
1 parent 38aea4c commit d27814c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/groonga/query-log/command/run-regression-test.rb
Expand Up @@ -46,6 +46,7 @@ def initialize
@skip_finished_queries = false
@output_query_log = false
@care_order = true
@verify_cachehit_mode = false
end

def run(command_line)
Expand Down Expand Up @@ -260,6 +261,10 @@ def ensure_database
end
end

def use_persistent_cache?
@groonga_options.include?("--cache-base-path")
end

def shutdown
begin
send_command("shutdown")
Expand All @@ -268,6 +273,14 @@ def shutdown
Process.waitpid(@pid)
end

def restart
self.shutdown
run_thread = Thread.new do
self.run{}
end
run_thread.join
end

private
def find_unused_port
server = TCPServer.new(@host, 0)
Expand Down Expand Up @@ -363,6 +376,12 @@ def run_test
rescue Interrupt
puts("Interrupt: #{query_log_path}")
end
if @new.use_persistent_cache?
@new.restart
end
if @old.use_persistent_cache?
@old.restart
end
end

old_thread = Thread.new do
Expand Down Expand Up @@ -390,6 +409,7 @@ def verify_server(test_log_path, query_log_path)
]
command_line << "--no-care-order" if @options[:care_order] == false
command_line << query_log_path.to_s
command_line << "--verify-cachehit-mode" if @new.use_persistent_cache? or @old.use_persistent_cache?
verify_server = VerifyServer.new
verify_server.run(command_line)
end
Expand Down
6 changes: 6 additions & 0 deletions lib/groonga/query-log/command/verify-server.rb
Expand Up @@ -135,6 +135,12 @@ def create_parser
@options.output_path = path
end

parser.on("--verify-cachehit-mode",
"Verify cachehit rate. After execute query, 'status' command execute.",
"[#{@options.verify_cachehit_mode}]") do
@options.verify_cachehit_mode = true
end

parser.separator("Debug options:")
parser.separator("")

Expand Down
6 changes: 6 additions & 0 deletions lib/groonga/query-log/response-comparer.rb
Expand Up @@ -36,6 +36,8 @@ def same?
case @command.name
when "select", "logical_select"
same_select_response?
when "status"
same_cache_hit_rate?
else
same_response?
end
Expand Down Expand Up @@ -71,6 +73,10 @@ def same_select_response?
end
end

def same_cache_hit_rate?
@response1.body["cache_hit_rate"] == @response2.body["cache_hit_rate"]
end

def care_order?
return false unless @options[:care_order]
return false if random_sort?
Expand Down
9 changes: 9 additions & 0 deletions lib/groonga/query-log/server-verifier.rb
Expand Up @@ -78,6 +78,9 @@ def run_consumer
begin
verify_command(groonga1_client, groonga2_client,
statistic.command)

verify_command(groonga1_client, groonga2_client,
Groonga::Command::Status.new)
rescue
log_client_error($!) do
$stderr.puts(statistic.command.original_source)
Expand Down Expand Up @@ -106,6 +109,9 @@ def target_command?(command)
end

def verify_command(groonga1_client, groonga2_client, command)
if command.instance_of?(Groonga::Command::Status)
return unless @options.verify_cachehit_mode
end
command["cache"] = "no" if @options.disable_cache?
command["output_type"] = :json
response1 = groonga1_client.execute(command)
Expand Down Expand Up @@ -148,6 +154,7 @@ class Options
attr_accessor :target_command_names
attr_accessor :output_path
attr_accessor :care_order
attr_accessor :verify_cachehit_mode
def initialize
@groonga1 = GroongaOptions.new
@groonga2 = GroongaOptions.new
Expand All @@ -164,8 +171,10 @@ def initialize
"normalize",
"object_exist",
"select",
"status",
]
@care_order = true
@verify_cahehit_mode = false
end

def request_queue_size
Expand Down

0 comments on commit d27814c

Please sign in to comment.