internethakai 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 0.2.3:
2
+ * 一定時間経過するまで無限に試験をつづける機能(total_duration)を追加。
3
+
1
4
  0.2.2:
2
5
  * ファイルからランダムに選択した変数を使用できる機能(var_file, var_name)を追加。
3
6
 
data/README CHANGED
@@ -29,6 +29,7 @@ CUIで使える高機能な負荷試験スクリプトです。
29
29
  [-l --loop] ループ回数を上書きします。
30
30
  [-g --log-level] ログレベルを上書きします。
31
31
  [-n --nth] n 番目のアクションだけを実行(0から数えます)。
32
+ [-d --duration] 持続時間を上書きします。
32
33
  [--test] テストモードで実行。テストモードで実行すると、強制的に並列数を1、ループ数1、1プロセス、ログレベル3で実行します。リクエストが正常に送られているか確認するために使用できます。
33
34
 
34
35
 
@@ -37,6 +38,7 @@ YAMLの連想配列で設定項目を指定します。指定すべきキー名
37
38
  まずは hakaigen コマンドによる自動生成を試してみてください。
38
39
 
39
40
  [loop] 各シナリオのループ回数を指定します。
41
+ [total_duration] 持続時間を指定します。total_durationを設定した場合、ループ回数は無視し、一定時間シナリオの実行をつづけます。単位は秒です。
40
42
  [max_request] HTTPクライアントの数を指定します。max_requestが10であればHTTPクライアントを10作成し、10のクライアントが同時にリクエストします。なおここで設定した値は全プロセスの合計値です。おすすめの値は "100" です(1プロセスあたり100コネクションくらいになるように調整しましょう)。
41
43
  [max_scenario] シナリオの数を指定します。デフォルトではmax_requestと同じ値になります。特に指定の必要はありませんが、アクセスするユーザーの数を増やしたい場合に多めに設定します。たとえば、max_requestが10、max_scenarioが20であれば、20*ループ数分のシナリオを10個のHTTPクラアントが順次実行していきます。<b>concurrencyというキー名から変更しました。</b>
42
44
  [log_level]
@@ -118,7 +120,7 @@ YAMLの連想配列で設定項目を指定します。指定すべきキー名
118
120
  ==== ファイルからランダムに取得
119
121
  user_id などをファイルからランダムに取得して使用できます。
120
122
  ファイルには改行区切りで、値のリストを書いておきます。シナリオごとに異なる値がセットされます。
121
- ファイルの名前、および変数の名前は var_file、var_name というキー名でセットしてください。
123
+ ファイルの名前、および変数の名前は var_file、var_name というキー名でセットします。
122
124
  var_file、var_name はactions の外に書きます。
123
125
 
124
126
  例.
@@ -126,7 +128,20 @@ YAMLの連想配列で設定項目を指定します。指定すべきキー名
126
128
  var_name: user_id
127
129
  actions:
128
130
  # user_id がファイルからランダムに選択される
129
- - path: /somepath?user_id=%(user_id)%
131
+ - path: /somepath?id=%(user_id)%
132
+
133
+ 複数のファイルを使用したい場合は以下のように書いてください。
134
+
135
+ 例.
136
+ vars:
137
+ - var_file: ./ids0
138
+ var_name: user_id
139
+ - var_file: ./ids1
140
+ var_name: item_id
141
+ actions:
142
+ # user_id と item_id がファイルからランダムに選択される
143
+ - path: /somepath?id=%(user_id)%
144
+ - path: /somepath?id=%(item_id)%
130
145
 
131
146
 
132
147
  ==== レスポンスで変数を設定
data/lib/internethakai.rb CHANGED
@@ -18,7 +18,7 @@ require 'internethakai/generator'
18
18
 
19
19
  module InternetHakai
20
20
  # インターネット破壊
21
- VERSION = '0.2.2'
21
+ VERSION = '0.2.3'
22
22
  GET="GET"
23
23
  POST="POST"
24
24
  PUT="PUT"
@@ -2,7 +2,9 @@ module InternetHakai
2
2
  # = httpクライアントをいじるクラス
3
3
  class ClientHandler
4
4
  UNIQUE_BY_THREAD = true
5
+ @@var_stores = {}
5
6
  def self::on_config_load config
7
+ @@var_stores = {}
6
8
  config['actions'] = config['actions'].map do |actconfig|
7
9
  actconfig['usr_var'] = false
8
10
  if(/%\(.*\)%/ =~ actconfig['path'])
@@ -13,19 +15,38 @@ module InternetHakai
13
15
  end
14
16
  actconfig
15
17
  end
18
+ # ファイルでセットする変数
16
19
  if(config.has_key?('var_file') && config.has_key?('var_name'))
17
20
  s = File::open(config['var_file']){|io|io.read}
21
+ var_ids = []
18
22
  if s
19
23
  lines = s.split("\n")
20
- @@var_ids = lines.sort_by{rand}
24
+ var_ids = lines.sort_by{rand}
21
25
  end
22
- @@var_name = config['var_name']
26
+ unless var_ids.empty?
27
+ var_name = config['var_name']
28
+ @@var_stores[var_name] = var_ids
29
+ end
30
+ end
31
+ # 複数ファイルの場合
32
+ if(config.has_key?('vars') && config['vars'].is_a?(Array))
33
+ config['vars'].each do |c|
34
+ next unless c.has_key?('var_file') && c.has_key?('var_name')
35
+ s = File::open(c['var_file']){|io|io.read}
36
+ next if s.nil? || s==''
37
+ ids = s.split("\n").sort_by{rand}
38
+ @@var_stores[c['var_name']] = ids unless ids.empty?
39
+ end
40
+ end
41
+ unless @@var_stores.empty?
23
42
  def set_var_id
24
- ids = @@var_ids
25
- id = ids[@performance_id % ids.size]
26
- set_var(@@var_name, id)
43
+ @@var_stores.each do |var_name, ids|
44
+ id = ids[@performance_id % ids.size]
45
+ set_var(var_name, id)
46
+ end
27
47
  end
28
48
  else
49
+ #変数がないときは何もしない
29
50
  def set_var_id
30
51
  end
31
52
  end
@@ -78,6 +99,8 @@ module InternetHakai
78
99
  def handle_client client
79
100
  @client = client
80
101
  end
102
+ def set_var_id
103
+ end
81
104
  end
82
105
 
83
106
  # = ケータイサイト用
@@ -76,10 +76,7 @@ module InternetHakai
76
76
  end
77
77
  rescue SystemExit
78
78
  return
79
- rescue Exception => e
80
- raise e
81
- puts "error: #{e.message}"
82
- puts e.backtrace[0]
79
+ rescue Interrupt => e
83
80
  if @fork_mode
84
81
  #死ぬ前に親に連絡
85
82
  Process::kill(:USR1, Process::ppid)
@@ -66,6 +66,13 @@ module InternetHakai
66
66
  #end
67
67
  sc.init
68
68
  end
69
+ if @config.has_key?('total_duration')
70
+ @config['infinity'] = true
71
+ timer = Rev::TimerWatcher::new(@config['total_duration'], false)
72
+ timer.on_timer(&method(:rev_on_complete))
73
+ timer.attach(Rev::Loop::default)
74
+ timer.enable unless timer.enabled?
75
+ end
69
76
 
70
77
  @threads[:main] = Thread::current
71
78
  @starttime = Time::now
@@ -9,6 +9,7 @@ module InternetHakai
9
9
  setting['max_request'] = args[:max_request] if args.has_key? :max_request
10
10
  setting['max_scenario'] = args[:concurrency] if args.has_key? :concurrency
11
11
  setting['log_level'] = args[:log_level] if args.has_key? :log_level
12
+ setting['duration'] = args[:duration] if args.has_key? :duration
12
13
  else
13
14
  setting = nil
14
15
  end
@@ -51,7 +52,11 @@ module InternetHakai
51
52
  @logger.run(start + "\n", 2)
52
53
  @logger.run("Rev Mode\n", 2) if @config['rev']
53
54
  @logger.run("Target domain = #{@config['domain']}\n", 2)
54
- @logger.run("Loop: #{@config['loop']}\n", 2)
55
+ if @config.has_key?('total_duration')
56
+ @logger.run("Duration: #{@config['total_duration']}\n", 2)
57
+ else
58
+ @logger.run("Loop: #{@config['loop']}\n", 2)
59
+ end
55
60
  @logger.run("Request Concurrency: #{@config['max_request_show']}\n", 2)
56
61
  @logger.run("Scenario Concurrency: #{@config['max_scenario_show']}\n", 2)
57
62
  end
@@ -83,6 +88,9 @@ module InternetHakai
83
88
  opts.on('-n NUM', '--nth', 'run only nth action') do |l|
84
89
  args[:action_nth] = l.to_i
85
90
  end
91
+ opts.on('-d NUM', '--duration', 'duration-time') do |l|
92
+ args[:duration] = l.to_i
93
+ end
86
94
  opts.on_tail("-h", "--help", "show this message") do
87
95
  puts opts
88
96
  exit
@@ -38,7 +38,13 @@ module InternetHakai
38
38
  if @action_counter == 0
39
39
  @loop -= 1
40
40
  #これで最後
41
- return if @loop == 0
41
+ if @loop == 0
42
+ if @config['infinity']
43
+ @loop += 100 # 無限ループ!
44
+ else
45
+ return
46
+ end
47
+ end
42
48
  @action_counter = @actions_size
43
49
  @performance_id = (@scenario_id.to_s + sprintf(@tmpl, @loop)).to_i
44
50
  end
@@ -72,6 +72,10 @@ module InternetHakai
72
72
  #ひとつのシナリオが終了
73
73
  @size -= 1
74
74
  #@logger.run("size:#{@size}\n", 2)
75
+ if @config['infinity']
76
+ @scenarios[scenario_id] += 100
77
+ return
78
+ end
75
79
  if @size==0
76
80
  @logger.run("O", 2)
77
81
  on_complete
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - takada-at