gargor 0.0.1 → 0.0.2

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/Gemfile CHANGED
@@ -3,6 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in gargor.gemspec
4
4
  gemspec
5
5
 
6
- require 'json'
7
- require 'jsonpath'
6
+ gem 'json'
7
+ gem 'jsonpath'
8
8
 
data/README.md CHANGED
@@ -12,7 +12,7 @@ Ruby 1.9以降が必要です
12
12
 
13
13
  1. 現在のChefの設定ファイル(JSON)から個体を一つ作ります。
14
14
  2. 残りの個体を突然変異により作ります。
15
- 3. 各個体に対し、負荷試験を実施し、適応値を算出します。
15
+ 3. 各個体に対し負荷試験(Chefによる配備→攻撃)を実施し、適応値を算出します。
16
16
  4. 現世代の個体群に対して、エリートと残りを交叉および突然変異により次世代の個体群をつくります。
17
17
  5. 次世代の個体群を現世代として`3.`に戻ります。これを指定した世代分実施します。
18
18
  6. 最後に最も高い適応値の個体をサーバに配備して終了します
@@ -20,12 +20,97 @@ Ruby 1.9以降が必要です
20
20
  ## 使い方
21
21
 
22
22
  $ gargor [dsl-file]
23
-
24
23
 
25
- `dsl-file`を省略した場合は、カレントディレクトリの`gargor.rb`を探します。
24
+ `gargor`の設定情報は、内部DSLによりに以下のように記述します。
26
25
 
27
- dsl-fileの書き方は、添付の`doc/sample.rb`を御覧ください
28
-
26
+ ```ruby
27
+ # 世代数: 1以上を指定してください
28
+ max_generations 10
29
+
30
+ # 個体数: 1世代あたりの個体数
31
+ population 10
32
+
33
+ # エリート: 世代交代の時に適応値の高い個体をそのまま次世代に引き継ぐ数
34
+ elite 1
35
+
36
+ # 突然変異の確率: "0.01"で"1%"
37
+ mutation 0.01
38
+
39
+ # ターゲットをChefで料理するコマンド %sには、ノード名が入る
40
+ target_cooking_cmd "knife solo cook %s"
41
+
42
+ # ターゲットのノード
43
+ # 攻撃前に以下のノードすべてに対してtarget_cooking_cmdが実施される
44
+ target_nodes ["www-1.example","www-2.example","db-1.example"]
45
+
46
+ # 攻撃コマンド
47
+ attack_cmd "ssh attacker.example ./bin/ghakai www-1.example.yml 2>/dev/null"
48
+
49
+
50
+ # 攻撃結果の評価
51
+ # code: attack_cmdのプロセス終了コード(普通は0:成功)
52
+ # out: attack_cmdの標準出力
53
+ # time: attack_cmdの実行時間
54
+ evaluate do |code,out,time|
55
+ puts out
56
+ fitness = 0
57
+
58
+ # 攻撃コマンドで使っている、グリーン破壊の標準出力から
59
+ # FAILEDの値を抜き出し0以外は適応値0としている
60
+ if time > 0 && code == 0 && /^FAILED (\d+)/ =~ out && $1 == "0"
61
+ # 攻撃コマンドで使っている、グリーン破壊の標準出力から
62
+ # 適応値に代用できそうなものを正規表現で取得する
63
+ # request count:200, concurrenry:20, 45.060816 req/s
64
+ if /, ([\.\d]+) req\/s/ =~ out
65
+ fitness = $1.to_f
66
+ end
67
+ # 単純に実行時間で適応値を設定したいなら以下のようにしても良い
68
+ # fitness = 1/time
69
+ end
70
+ # このブロックは必ず適応値を返すこと(整数or浮動小数)
71
+ fitness
72
+ end
73
+
74
+ # パラメータ定義
75
+ # GAにより変動されるパラメータをここで定義する
76
+ #
77
+ # param 名前 do
78
+ # json_file: 値を上書くJSONファイル nodes/*.jsonやroles/*.json
79
+ # (注意!) gargorはこのjsonファイルを容赦なく書き換える
80
+ # json_path: json_fileの中から書変える値の場所をJSONPath形式で指定する
81
+ # mutaion: 突然変異時の値の設定
82
+ param "max_clients" do
83
+ json_file "roles/www.json"
84
+ json_path '$.httpd.max_clients'
85
+ mutation rand(500)+10
86
+ end
87
+
88
+ param "innodb_log_file_size" do
89
+ json_file "nodes/db-1.example.json"
90
+ json_path '$.mysqld.innodb_log_file_size'
91
+ mutation rand(200)
92
+ end
93
+
94
+ param "sort_buffer_size" do
95
+ json_file "nodes/db-1.example.json"
96
+ json_path '$.mysqld.sort_buffer_size'
97
+ mutation rand(1000)
98
+ end
99
+
100
+ param "read_buffer_size" do
101
+ json_file "nodes/db-1.example.json"
102
+ json_path '$.mysqld.read_buffer_size'
103
+ mutation rand(1000)
104
+ end
105
+
106
+ param "query_cache_size" do
107
+ json_file "nodes/db-1.example.json"
108
+ json_path '$.mysqld.query_cache_size'
109
+ mutation rand(100)
110
+ end
111
+ ```
112
+
113
+ このDSLファイルは任意のファイル名でChefのリポジトリに含めてしまうことを推奨します。`dsl-file`を省略した場合は、カレントディレクトリの`gargor.rb`を探します。
29
114
 
30
115
  ### 注意
31
116
 
@@ -150,11 +235,11 @@ MaxRequestsPerChild <%= node["httpd"]["max_request_per_child"] %>
150
235
 
151
236
  コマンドラインで使えるものであれば、大体使うことができます。サンプルでは、[グリーン破壊](https://github.com/KLab/green-hakai/)を使わせて頂きました。
152
237
 
153
- 負荷試験の厳しさによって個体が死滅することがあります。すると以下のように表示され、プログラムが終了します。
238
+ 負荷試験の厳しさによって個体が全滅することがあります。すると以下のように表示され、プログラムが終了します。
154
239
 
155
240
  ***** EXTERMINATION ******
156
241
 
157
- これは、個体の環境が厳しすぎるためで負荷試験を緩めて再度実施してください。
242
+ これは、個体の環境が厳しすぎるためで負荷の条件を緩めて再度実施してください。
158
243
 
159
244
  ## FAQ
160
245
 
data/bin/gargor CHANGED
@@ -4,8 +4,18 @@ require 'gargor'
4
4
 
5
5
  dsl_file=ARGV.last||"gargor.rb"
6
6
 
7
- Gargor.start
8
- Gargor.load_dsl(dsl_file)
7
+ def usage
8
+ STDERR.print "usage: #{$0} [dsl-file]\n"
9
+ end
10
+
11
+ begin
12
+ Gargor.start
13
+ Gargor.load_dsl(dsl_file)
14
+ rescue
15
+ usage
16
+ exit 1
17
+ end
18
+
9
19
  loop {
10
20
  Gargor.populate.each { |i|
11
21
  if i.fitness == nil
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Gargor::VERSION
9
9
  spec.authors = ["Yoshihiro TAKAHARA"]
10
10
  spec.email = ["y.takahara@gmail.com"]
11
- spec.description = %q{auto server tunner by generic algorithm}
12
- spec.summary = %q{auto server tunner by generic algorithm using chef}
11
+ spec.description = %q{It is software which uses generic algorithm to support parameter tuning of the servers controlled by Chef.}
12
+ spec.summary = %q{An auto-tuning tool for internet servers w/ Genetic Algorithm and Chef. You can get good settings during sleeping ;) }
13
13
  spec.homepage = "https://github.com/tumf/gargor"
14
14
  spec.license = "MIT"
15
15
 
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
3
  require "gargor/version"
3
4
  require "gargor/individual"
4
5
  require "gargor/parameter"
@@ -20,18 +21,20 @@ class Gargor
20
21
  @@prev_generation = nil
21
22
  @@individuals = []
22
23
  @@param_procs = {}
23
- @@population = 10
24
+ @@population = 0
24
25
  @@max_generations = 1
25
26
  @@generation = 1
26
27
  @@elite = 0
27
28
  @@attack_cmd = "false"
28
29
  @@attack_proc = nil
29
- @@evaluate_proc = nil
30
+ @@evaluate_proc = Proc.new { 0 }
31
+ @@target_nodes = []
30
32
  end
31
33
 
32
34
  def load_dsl(params_file)
33
35
  contents = File.open(params_file, 'rb'){ |f| f.read }
34
36
  new.instance_eval(contents)
37
+ raise "POPULATION == 0" if @@population == 0
35
38
  end
36
39
 
37
40
  def mutation
@@ -1,3 +1,3 @@
1
1
  class Gargor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gargor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-16 00:00:00.000000000 Z
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -43,7 +43,8 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: auto server tunner by generic algorithm
46
+ description: It is software which uses generic algorithm to support parameter tuning
47
+ of the servers controlled by Chef.
47
48
  email:
48
49
  - y.takahara@gmail.com
49
50
  executables:
@@ -86,5 +87,6 @@ rubyforge_project:
86
87
  rubygems_version: 1.8.25
87
88
  signing_key:
88
89
  specification_version: 3
89
- summary: auto server tunner by generic algorithm using chef
90
+ summary: An auto-tuning tool for internet servers w/ Genetic Algorithm and Chef. You
91
+ can get good settings during sleeping ;)
90
92
  test_files: []