[Groonga-commit] droonga/drnbench at a404a77 [master] Accept multiple default hosts for load balancing

Back to archive index

SHIMODA Piro Hiroshi null+****@clear*****
Sat Oct 4 01:24:16 JST 2014


SHIMODA "Piro" Hiroshi	2014-10-04 01:24:16 +0900 (Sat, 04 Oct 2014)

  New Revision: a404a772a4ea00b819d2691854b720a2f80b4b6f
  https://github.com/droonga/drnbench/commit/a404a772a4ea00b819d2691854b720a2f80b4b6f

  Message:
    Accept multiple default hosts for load balancing

  Modified files:
    bin/drnbench-request-response
    lib/drnbench/request-response/configuration.rb

  Modified: bin/drnbench-request-response (+8 -3)
===================================================================
--- bin/drnbench-request-response    2014-10-04 01:04:34 +0900 (13c1b94)
+++ bin/drnbench-request-response    2014-10-04 01:24:16 +0900 (39cc6b4)
@@ -78,9 +78,9 @@ option_parser = OptionParser.new do |parser|
     config.request_patterns_file = File.expand_path(path)
   end
 
-  parser.on("--default-host=HOST", String,
-            "Default host name for each request.",
-            "(#{config.default_host})") do |host|
+  parser.on("--default-hosts=HOST1,HOST2,...", Array,
+            "Default host names for each request.",
+            "(#{config.default_hosts.join(",")})") do |hosts|
     config.default_host = host
   end
   parser.on("--default-port=PORT", Integer,
@@ -103,6 +103,11 @@ option_parser = OptionParser.new do |parser|
             "(#{config.default_timeout})") do |timeout|
     config.default_timeout = timeout
   end
+  parser.on("--default-host=HOST1,HOST2,...", Array,
+            "An alias to \"--default-hosts\"",
+            "for backward compatibility.") do |hosts|
+    config.default_hosts = hosts
+  end
 
   parser.separator("")
   parser.separator("Output:")

  Modified: lib/drnbench/request-response/configuration.rb (+19 -2)
===================================================================
--- lib/drnbench/request-response/configuration.rb    2014-10-04 01:04:34 +0900 (f9c1bd4)
+++ lib/drnbench/request-response/configuration.rb    2014-10-04 01:24:16 +0900 (3941d0e)
@@ -21,7 +21,8 @@ module Drnbench
       attr_accessor :duration, :wait, :interval, :request_patterns_file
       attr_accessor :start_n_clients, :end_n_clients, :step, :n_requests, :n_slow_requests
       attr_accessor :mode
-      attr_accessor :default_host, :default_port, :default_path, :default_method, :default_timeout
+      attr_reader   :default_hosts
+      attr_accessor :default_port, :default_path, :default_method, :default_timeout
       attr_accessor :report_progressively, :output_path
 
       MIN_DURATION = 1
@@ -38,7 +39,7 @@ module Drnbench
         @mode                 = :http
         @n_slow_requests      = 5
 
-        @default_host         = "localhost"
+        @default_hosts        = ["localhost"]
         @default_port         = 80
         @default_path         = "/"
         @default_method       = "GET"
@@ -46,6 +47,8 @@ module Drnbench
 
         @report_progressively = true
         @output_path          = "/tmp/drnbench-result.csv"
+
+        @last_default_host_index = 0
       end
 
       def validate
@@ -73,6 +76,20 @@ module Drnbench
         @request_patterns ||= prepare_request_patterns
       end
 
+      def default_hosts=(hosts)
+        @last_default_host_index = 0
+        @default_hosts = hosts
+      end
+
+      def default_host
+        host = @default_hosts[@last_default_host_index]
+        @last_default_host_index += 1
+        if @last_default_host_index == @default_hosts.size
+          @last_default_host_index = 0
+        end
+        host
+      end
+
       private
       def prepare_request_patterns
         request_patterns = File.read(@request_patterns_file)
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index