YUKI Hiroshi
null+****@clear*****
Mon Oct 7 16:26:24 JST 2013
YUKI Hiroshi 2013-10-07 16:26:24 +0900 (Mon, 07 Oct 2013) New Revision: 9157d194b4fe4351cc861a375189cc137dbb7f00 https://github.com/droonga/http-benchmark/commit/9157d194b4fe4351cc861a375189cc137dbb7f00 Message: Add options to define default host, port, path and HTTP method Modified files: bin/http-benchmark lib/droonga/http-benchmark.rb Modified: bin/http-benchmark (+27 -6) =================================================================== --- bin/http-benchmark 2013-10-07 15:50:42 +0900 (8780d61) +++ bin/http-benchmark 2013-10-07 16:26:24 +0900 (ac80ba3) @@ -14,9 +14,26 @@ option_parser = OptionParser.new do |parser| "wait for each request") do |wait| options[:wait] = wait end - parser.on("--n-threads=N", Integer, - "number of threads") do |n_threads| - options[:n_threads] = n_threads + parser.on("--n-clients=N", Integer, + "number of clients") do |n_clients| + options[:n_clients] = n_clients + end + + parser.on("--host=HOST", String, + "default host name (optional)") do |host| + options[:host] = host + end + parser.on("--port=PORT", Integer, + "default port number (optional)") do |port| + options[:port] = port + end + parser.on("--path=PATH", String, + "default path (optional)") do |path| + options[:path] = path + end + parser.on("--method=METHOD", String, + "default HTTP method (optional)") do |method| + options[:method] = method end end args = option_parser.parse!(ARGV) @@ -24,11 +41,15 @@ args = option_parser.parse!(ARGV) if options[:duration].nil? raise "You must specify the test duration by --duration option." end -if options[:threads].nil? - raise "You must specify the count of request threads by --threads option." +if options[:clients].nil? + raise "You must specify the number of clients by --clients option." end benchmark = Droonga::HttpBenchmark.new(:duration => options[:duration], :wait => options[:wait], - :n_threads => options[:n_threads]) + :n_clients => options[:n_clients], + :host => options[:host], + :port => options[:port], + :path => options[:path], + :method => options[:method]) benchmark.run Modified: lib/droonga/http-benchmark.rb (+24 -5) =================================================================== --- lib/droonga/http-benchmark.rb 2013-10-07 15:50:42 +0900 (084e878) +++ lib/droonga/http-benchmark.rb 2013-10-07 16:26:24 +0900 (349b99a) @@ -1,20 +1,33 @@ # -*- coding: utf-8 -*- +require "thread" +require "net/http" +require "json" + class HttpBenchmark - attr_reader :duration, :threads_count + attr_reader :duration, :n_clients MIN_DURATION = 1.0 MIN_WAIT = 0 - MAX_N_THREADS = 16 - + MAX_N_CLIENTS = 16 TOTAL_N_REQUESTS = 1000, + DEFAULT_HOST = "localhost" + DEFAULT_PORT = 80 + DEFAULT_PATH = "/" + DEFAULT_METHOD = "GET" + def initialize(params) @duration = [params[:duration], MIN_DURATION].max @wait = [params[:wait], MIN_WAIT].max - @n_threads = [params[:n_threads], MAX_N_THREADS].min + @n_clients = [params[:n_clients], MAX_N_CLIENTS].min @n_requests = params[:n_requests] || TOTAL_N_REQUESTS + @default_host = params[:host] || DEFAULT_HOST + @default_port = params[:port] || DEFAULT_PORT + @default_path = params[:path] || DEFAULT_PATH + @default_method = params[:method] || DEFAULT_METHOD + if params[:request_pattern] params[:request_pattern][:frequency] = 1 @request_patterns = [params[:request_pattern]] @@ -53,7 +66,13 @@ class HttpBenchmark base_patterns = base_patterns.shuffle 0.upto(n_requests) do |count| - @requests << base_patterns[count % base_patterns.size] + request = base_patterns[count % base_patterns.size] + request[:host] ||= @default_host + request[:port] ||= @default_port + request[:path] ||= @default_path + request[:method] ||= @default_method + request[:method] = request[:method].upcase + @requests << request end end end -------------- next part -------------- HTML����������������������������...ダウンロード