fairy 0.6.0

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.
Files changed (186) hide show
  1. data/LICENSE +674 -0
  2. data/Makefile +116 -0
  3. data/README +15 -0
  4. data/bin/fairy +582 -0
  5. data/bin/fairy-cat +74 -0
  6. data/bin/fairy-cp +128 -0
  7. data/bin/fairy-rm +122 -0
  8. data/bin/subcmd/controller +41 -0
  9. data/bin/subcmd/inspector +81 -0
  10. data/bin/subcmd/master +43 -0
  11. data/bin/subcmd/node +47 -0
  12. data/bin/subcmd/processor +54 -0
  13. data/doc/programming-interface.html +240 -0
  14. data/doc/programming-interface.rd +300 -0
  15. data/etc/fairy.conf.tmpl +118 -0
  16. data/ext/simple_hash/extconf.rb +4 -0
  17. data/ext/simple_hash/simple_hash.c +42 -0
  18. data/fairy.gemspec +60 -0
  19. data/lib/fairy/client/addins.rb +20 -0
  20. data/lib/fairy/client/barrier.rb +29 -0
  21. data/lib/fairy/client/basic-group-by.rb +52 -0
  22. data/lib/fairy/client/cat.rb +41 -0
  23. data/lib/fairy/client/direct-product.rb +51 -0
  24. data/lib/fairy/client/equijoin.rb +79 -0
  25. data/lib/fairy/client/exec.rb +54 -0
  26. data/lib/fairy/client/filter.rb +62 -0
  27. data/lib/fairy/client/find.rb +35 -0
  28. data/lib/fairy/client/group-by.rb +194 -0
  29. data/lib/fairy/client/here.rb +84 -0
  30. data/lib/fairy/client/inject.rb +70 -0
  31. data/lib/fairy/client/input-file.rb +53 -0
  32. data/lib/fairy/client/input-iota.rb +49 -0
  33. data/lib/fairy/client/input-local-file.rb +188 -0
  34. data/lib/fairy/client/input-varray.rb +30 -0
  35. data/lib/fairy/client/input.rb +42 -0
  36. data/lib/fairy/client/io-filter.rb +26 -0
  37. data/lib/fairy/client/junction.rb +31 -0
  38. data/lib/fairy/client/map.rb +34 -0
  39. data/lib/fairy/client/merge-group-by.rb +71 -0
  40. data/lib/fairy/client/output-file.rb +64 -0
  41. data/lib/fairy/client/output-local-file.rb +60 -0
  42. data/lib/fairy/client/output-null.rb +47 -0
  43. data/lib/fairy/client/output-varray.rb +50 -0
  44. data/lib/fairy/client/output.rb +29 -0
  45. data/lib/fairy/client/roma-put.rb +62 -0
  46. data/lib/fairy/client/roma.rb +156 -0
  47. data/lib/fairy/client/seg-join.rb +61 -0
  48. data/lib/fairy/client/seg-map.rb +78 -0
  49. data/lib/fairy/client/seg-shuffle.rb +35 -0
  50. data/lib/fairy/client/seg-split.rb +27 -0
  51. data/lib/fairy/client/seg-zip.rb +60 -0
  52. data/lib/fairy/client/select.rb +38 -0
  53. data/lib/fairy/client/sort.rb +48 -0
  54. data/lib/fairy/client/sort18.rb +56 -0
  55. data/lib/fairy/client/sort19.rb +61 -0
  56. data/lib/fairy/client/there.rb +47 -0
  57. data/lib/fairy/client/top_n_into_roma.rb +34 -0
  58. data/lib/fairy/client/wc.rb +92 -0
  59. data/lib/fairy/controller.rb +1103 -0
  60. data/lib/fairy/logger.rb +107 -0
  61. data/lib/fairy/master/addins.rb +20 -0
  62. data/lib/fairy/master/atom.rb +17 -0
  63. data/lib/fairy/master/c-barrier.rb +283 -0
  64. data/lib/fairy/master/c-basic-group-by.rb +250 -0
  65. data/lib/fairy/master/c-cat.rb +159 -0
  66. data/lib/fairy/master/c-direct-product.rb +203 -0
  67. data/lib/fairy/master/c-exec.rb +68 -0
  68. data/lib/fairy/master/c-filter.rb +422 -0
  69. data/lib/fairy/master/c-find.rb +138 -0
  70. data/lib/fairy/master/c-group-by.rb +64 -0
  71. data/lib/fairy/master/c-here.rb +80 -0
  72. data/lib/fairy/master/c-inject.rb +119 -0
  73. data/lib/fairy/master/c-input-file.rb +46 -0
  74. data/lib/fairy/master/c-input-iota.rb +66 -0
  75. data/lib/fairy/master/c-input-local-file.rb +117 -0
  76. data/lib/fairy/master/c-input-varray.rb +53 -0
  77. data/lib/fairy/master/c-input.rb +24 -0
  78. data/lib/fairy/master/c-inputtable.rb +31 -0
  79. data/lib/fairy/master/c-inputtable18.rb +36 -0
  80. data/lib/fairy/master/c-inputtable19.rb +35 -0
  81. data/lib/fairy/master/c-io-filter.rb +28 -0
  82. data/lib/fairy/master/c-junction.rb +54 -0
  83. data/lib/fairy/master/c-map.rb +27 -0
  84. data/lib/fairy/master/c-merge-group-by.rb +241 -0
  85. data/lib/fairy/master/c-output-file.rb +84 -0
  86. data/lib/fairy/master/c-output-local-file.rb +19 -0
  87. data/lib/fairy/master/c-output-null.rb +45 -0
  88. data/lib/fairy/master/c-output-varray.rb +57 -0
  89. data/lib/fairy/master/c-output.rb +20 -0
  90. data/lib/fairy/master/c-seg-join.rb +141 -0
  91. data/lib/fairy/master/c-seg-map.rb +26 -0
  92. data/lib/fairy/master/c-seg-shuffle.rb +87 -0
  93. data/lib/fairy/master/c-seg-split.rb +110 -0
  94. data/lib/fairy/master/c-seg-zip.rb +132 -0
  95. data/lib/fairy/master/c-select.rb +27 -0
  96. data/lib/fairy/master/c-sort.rb +108 -0
  97. data/lib/fairy/master/c-there.rb +57 -0
  98. data/lib/fairy/master/c-wc.rb +232 -0
  99. data/lib/fairy/master/job-interpriter.rb +19 -0
  100. data/lib/fairy/master/scheduler.rb +24 -0
  101. data/lib/fairy/master.rb +329 -0
  102. data/lib/fairy/node/addins.rb +19 -0
  103. data/lib/fairy/node/p-barrier.rb +95 -0
  104. data/lib/fairy/node/p-basic-group-by.rb +252 -0
  105. data/lib/fairy/node/p-direct-product.rb +153 -0
  106. data/lib/fairy/node/p-exec.rb +30 -0
  107. data/lib/fairy/node/p-filter.rb +363 -0
  108. data/lib/fairy/node/p-find.rb +111 -0
  109. data/lib/fairy/node/p-group-by.rb +1534 -0
  110. data/lib/fairy/node/p-here.rb +21 -0
  111. data/lib/fairy/node/p-identity.rb +24 -0
  112. data/lib/fairy/node/p-inject.rb +127 -0
  113. data/lib/fairy/node/p-input-file.rb +108 -0
  114. data/lib/fairy/node/p-input-iota.rb +39 -0
  115. data/lib/fairy/node/p-input-local-file.rb +61 -0
  116. data/lib/fairy/node/p-input-varray.rb +26 -0
  117. data/lib/fairy/node/p-io-filter.rb +28 -0
  118. data/lib/fairy/node/p-map.rb +40 -0
  119. data/lib/fairy/node/p-merger-group-by.rb +48 -0
  120. data/lib/fairy/node/p-output-file.rb +104 -0
  121. data/lib/fairy/node/p-output-local-file.rb +14 -0
  122. data/lib/fairy/node/p-output-null.rb +32 -0
  123. data/lib/fairy/node/p-output-varray.rb +41 -0
  124. data/lib/fairy/node/p-seg-join.rb +82 -0
  125. data/lib/fairy/node/p-seg-map.rb +34 -0
  126. data/lib/fairy/node/p-seg-split.rb +61 -0
  127. data/lib/fairy/node/p-seg-zip.rb +79 -0
  128. data/lib/fairy/node/p-select.rb +40 -0
  129. data/lib/fairy/node/p-single-exportable.rb +90 -0
  130. data/lib/fairy/node/p-sort.rb +195 -0
  131. data/lib/fairy/node/p-task.rb +113 -0
  132. data/lib/fairy/node/p-there.rb +44 -0
  133. data/lib/fairy/node/p-wc.rb +266 -0
  134. data/lib/fairy/node.rb +187 -0
  135. data/lib/fairy/processor.rb +510 -0
  136. data/lib/fairy/share/base-app.rb +114 -0
  137. data/lib/fairy/share/block-source.rb +234 -0
  138. data/lib/fairy/share/conf.rb +396 -0
  139. data/lib/fairy/share/debug.rb +21 -0
  140. data/lib/fairy/share/encoding.rb +17 -0
  141. data/lib/fairy/share/fast-tempfile.rb +93 -0
  142. data/lib/fairy/share/file-place.rb +176 -0
  143. data/lib/fairy/share/hash-1.rb +20 -0
  144. data/lib/fairy/share/hash-md5.rb +28 -0
  145. data/lib/fairy/share/hash-murmur.rb +69 -0
  146. data/lib/fairy/share/hash-rb18.rb +20 -0
  147. data/lib/fairy/share/hash-simple-hash.rb +28 -0
  148. data/lib/fairy/share/inspector.rb +16 -0
  149. data/lib/fairy/share/lc/exceptions.rb +82 -0
  150. data/lib/fairy/share/lc/ja/exceptions.rb +81 -0
  151. data/lib/fairy/share/locale.rb +17 -0
  152. data/lib/fairy/share/log.rb +215 -0
  153. data/lib/fairy/share/pool-dictionary.rb +53 -0
  154. data/lib/fairy/share/port-marshaled-queue.rb +347 -0
  155. data/lib/fairy/share/port.rb +1697 -0
  156. data/lib/fairy/share/reference.rb +45 -0
  157. data/lib/fairy/share/stdout.rb +56 -0
  158. data/lib/fairy/share/tr.rb +16 -0
  159. data/lib/fairy/share/varray.rb +147 -0
  160. data/lib/fairy/share/vfile.rb +183 -0
  161. data/lib/fairy/version.rb +8 -0
  162. data/lib/fairy.rb +206 -0
  163. data/sample/grep.rb +46 -0
  164. data/sample/ping.rb +19 -0
  165. data/sample/sort.rb +102 -0
  166. data/sample/wordcount.rb +61 -0
  167. data/spec/README +12 -0
  168. data/spec/fairy1_spec.rb +31 -0
  169. data/spec/fairy2_spec.rb +42 -0
  170. data/spec/fairy3_spec.rb +126 -0
  171. data/spec/fairy4_spec.rb +63 -0
  172. data/spec/fairy5_spec.rb +45 -0
  173. data/spec/fairy6_spec.rb +52 -0
  174. data/spec/fairy7_spec.rb +58 -0
  175. data/spec/fairy8_spec.rb +48 -0
  176. data/spec/mkdat.rb +148 -0
  177. data/spec/run_all.sh +65 -0
  178. data/test/testc.rb +7111 -0
  179. data/tools/cap_recipe/Capfile +144 -0
  180. data/tools/cap_recipe/cluster.yml.sample +14 -0
  181. data/tools/fairy_perf_graph.rb +444 -0
  182. data/tools/git-tag +44 -0
  183. data/tools/log-analysis.rb +62 -0
  184. data/tools/svn-ls-diff +38 -0
  185. data/tools/svn-tags +37 -0
  186. metadata +298 -0
@@ -0,0 +1,266 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (C) 2007-2010 Rakuten, Inc.
4
+ #
5
+
6
+ require "fairy/node/p-io-filter"
7
+
8
+ require "fairy/share/file-place"
9
+
10
+ module Fairy
11
+ class PWC<PIOFilter
12
+ Processor.def_export self
13
+
14
+ ST_ALL_IMPORTED = :ST_ALL_IMPORTED
15
+ ST_WAIT_EXPORT_FINISH = :ST_WAIT_EXPORT_FINISH
16
+ ST_EXPORT_FINISH = :ST_EXPORT_FINISH
17
+
18
+ def PWC.open(processor, bjob, opts, fn)
19
+ nfile = PWC.new(processor, bjob, opts)
20
+ nfile.open(fn)
21
+ end
22
+
23
+ def initialize(id, ntask, bjob, opts=nil)
24
+ super
25
+ @file = nil
26
+
27
+ @exports = {}
28
+ @exports_queue = Queue.new
29
+
30
+ @counter = {}
31
+
32
+ @mod = opts[:no_segment]
33
+ @mod ||= CONF.GROUP_BY_NO_SEGMENT
34
+
35
+ mod = opts[:hash_module]
36
+ mod ||= CONF.GROUP_BY_HASH_MODULE
37
+ require mod
38
+ @hash_generator = Fairy::HValueGenerator.new(bjob.hash_seed)
39
+
40
+ @hash_optimize = CONF.GROUP_BY_GROUPING_OPTIMIZE
41
+ @hash_optimize = opts[:grouping_optimize] if opts.key?(:grouping_optimize)
42
+ end
43
+
44
+ def open(nfileplace)
45
+ @file_name = nfileplace.path
46
+ self.no = nfileplace.no
47
+ begin
48
+ @file = File.open(@file_name)
49
+ rescue
50
+ e = $!.exception($!.message+ "(vfile entry##{nfileplace.no}: #{nfileplace.url})")
51
+ e.set_backtrace($!.backtrace)
52
+
53
+ Log::error_exception(e)
54
+ handle_exception(e)
55
+ raise e
56
+ end
57
+ # start
58
+ self
59
+ end
60
+ DeepConnect::def_method_spec(self, "REF open(VAL)")
61
+
62
+ def add_export(key, export)
63
+ @exports[key] = export
64
+ # @exports_queue.push [key, export]
65
+ # [BUG#171]同期処理でないとまずい.
66
+ @bjob.add_exports(key, export, self)
67
+ end
68
+
69
+ def start_export
70
+ Log::debug(self, "START_EXPORT")
71
+
72
+ start do
73
+ hash_opt = @opts[:grouping_optimize]
74
+ hash_opt = CONF.GROUP_BY_GROUPING_OPTIMIZE if hash_opt.nil?
75
+
76
+ # if hash_opt
77
+ @key_proc = eval("proc{|w| w}", @context.binding)
78
+ # else
79
+ # @key_proc = BBlock.new("|w| w", @context, self)
80
+ # end
81
+
82
+ policy = @opts[:postqueuing_policy]
83
+ begin
84
+ @file.each do |ln|
85
+ (begin
86
+ ln.chomp.split
87
+ rescue
88
+ []
89
+ end).each do |e|
90
+ key = hash_key(e)
91
+ export = @exports[key]
92
+ unless export
93
+ export = Export.new(policy)
94
+ export.njob_id = @id
95
+ export.add_key(key)
96
+ add_export(key, export)
97
+ @counter[key] = 0
98
+ end
99
+ export.push e
100
+ @counter[key] += 1
101
+ end
102
+ end
103
+ rescue
104
+ Log::debug_exception(self)
105
+ raise
106
+ ensure
107
+ @exports_queue.push nil
108
+ @exports.each{|key, export|
109
+ Log::debug(self, "G0 #{key} => #{@counter[key]}")
110
+ export.push END_OF_STREAM}
111
+ end
112
+ end
113
+ end
114
+
115
+ def terminate
116
+ @wait_cv = @terminate_mon.new_cv
117
+ wait_export_finish
118
+ super
119
+ end
120
+
121
+ def hash_key(e)
122
+ @hash_generator.value(@key_proc.yield(e)) % @mod
123
+ end
124
+
125
+
126
+ def wait_export_finish
127
+
128
+ Log::debug(self, "G1")
129
+
130
+ self.status = ST_ALL_IMPORTED
131
+
132
+ Log::debug(self, "G2")
133
+ # すべての, exportのoutputが設定されるまで待っている
134
+ # かなりイマイチ
135
+ # for key, export in @exports
136
+ #Log::debug(self, "G2.key = #{export.key}: WAIT")
137
+ # export.output
138
+ #Log::debug(self, "G2.key = #{export.key}: RESUME")
139
+ # end
140
+
141
+ Log::debug(self, "G3")
142
+ # ここの位置が重要
143
+ self.status = ST_WAIT_EXPORT_FINISH
144
+ # ここもいまいち
145
+ Log::debug(self, "G4")
146
+ for key, export in @exports
147
+ Log::debug(self, "G4.WAIT #{key}")
148
+ export.fib_wait_finish(@wait_cv)
149
+ end
150
+ Log::debug(self, "G5")
151
+ self.status = ST_EXPORT_FINISH
152
+ end
153
+
154
+ class PPostFilter<PIOFilter
155
+ Processor.def_export self
156
+
157
+ ST_OUTPUT_FINISH = :ST_OUTPUT_FINISH
158
+
159
+ def initialize(id, ntask, bjob, opt, vf)
160
+ super
161
+ @vfile = vf
162
+
163
+ @buffering_policy = @opts[:buffering_policy]
164
+ @buffering_policy ||= CONF.GROUP_BY_BUFFERING_POLICY
165
+
166
+ @mod = @opts[:no_segment]
167
+ @mod ||= CONF.GROUP_BY_NO_SEGMENT
168
+
169
+ mod = @opts[:hash_module]
170
+ mod ||= CONF.GROUP_BY_HASH_MODULE
171
+ require mod
172
+ @hash_generator = Fairy::HValueGenerator.new(bjob.hash_seed)
173
+
174
+ @hash_optimize = CONF.GROUP_BY_GROUPING_OPTIMIZE
175
+ @hash_optimize = @opts[:grouping_optimize] if @opts.key?(:grouping_optimize)
176
+ end
177
+
178
+ def input=(input)
179
+ super
180
+ start
181
+ end
182
+
183
+ def hash_key(e)
184
+ @hash_proc.yield(e)
185
+ end
186
+
187
+ def basic_start(&block)
188
+ Log::debug(self, "START")
189
+ output_uri = gen_real_file_name
190
+ @vfile.set_real_file(no, output_uri)
191
+
192
+ Log::debug(self, "write real file: #{output_uri}")
193
+ begin
194
+ output_file = URI.parse(output_uri).path
195
+ rescue
196
+ Log::debug_exception(self)
197
+ raise
198
+ end
199
+
200
+ unless File.exist?(File.dirname(output_file))
201
+ create_dir(File.dirname(output_file))
202
+ end
203
+
204
+ @key_value_buffer =
205
+ eval("PGroupBy::#{@buffering_policy[:buffering_class]}").new(self, @buffering_policy)
206
+ # if @hash_optimize
207
+ @hash_proc = eval("proc{|w| w}")
208
+ # else
209
+ # @hash_proc = BBlock.new("|w| w", @context, self)
210
+ # end
211
+
212
+ @input.each do |e|
213
+ @key_value_buffer.push(e)
214
+ e = nil
215
+ end
216
+
217
+ File.open(output_file, "w") do |io|
218
+ Log::debug(self, "start write real file: #{output_uri}")
219
+ @key_value_buffer.each do |values|
220
+ io.puts [values.key, values.size].join(" ")
221
+ end
222
+ @key_value_buffer = nil
223
+ Log::debug(self, "finish write real file: #{output_uri}")
224
+ end
225
+
226
+ self.status = ST_OUTPUT_FINISH
227
+ end
228
+
229
+ def create_dir(path)
230
+ unless File.exist?(File.dirname(path))
231
+ create_dir(File.dirname(path))
232
+ end
233
+ begin
234
+ Dir.mkdir(path)
235
+ rescue Errno::EEXIST
236
+ # 無視
237
+ end
238
+ end
239
+
240
+ IPADDR_REGEXP = /::ffff:([0-9]+\.){3}[0-9]+|[0-9a-f]+:([0-9a-f]*:)[0-9a-f]*/
241
+
242
+ def gen_real_file_name
243
+ host= processor.addr
244
+ root = CONF.VF_ROOT
245
+ prefix = CONF.VF_PREFIX
246
+ base_name = @vfile.base_name
247
+ no = @input.no
248
+
249
+
250
+ if IPADDR_REGEXP =~ host
251
+ begin
252
+ host = Resolv.getname(host)
253
+ rescue
254
+ # ホスト名が分からない場合 は そのまま ipv6 アドレスにする
255
+ host = "[#{host}]"
256
+ end
257
+ end
258
+
259
+ format("file://#{host}#{root}/#{prefix}/#{base_name}-%03d", no)
260
+ end
261
+
262
+ end
263
+ end
264
+ end
265
+
266
+
data/lib/fairy/node.rb ADDED
@@ -0,0 +1,187 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (C) 2007-2010 Rakuten, Inc.
4
+ #
5
+
6
+ #require "monitor"
7
+
8
+ require "timeout"
9
+
10
+ require "deep-connect"
11
+
12
+ require "fairy/version"
13
+ require "fairy/share/conf"
14
+
15
+ #DeepConnect::Organizer.immutable_classes.push Array
16
+
17
+ module Fairy
18
+ class Node
19
+
20
+ def initialize
21
+ @id = nil
22
+ @addr = nil
23
+ @logger = nil
24
+
25
+ @processor_seq = -1
26
+ @processor_seq_mutex = Mutex.new
27
+
28
+ @processors = []
29
+ @processors_mutex = Mutex.new
30
+ @processors_cv = ConditionVariable.new
31
+
32
+ @active_processors = {}
33
+ @active_processors_mutex = Mutex.new
34
+ @active_processors_cv = ConditionVariable.new
35
+ end
36
+
37
+ attr_accessor :id
38
+ attr_accessor :addr
39
+ attr_reader :logger
40
+
41
+ attr_reader :processors
42
+
43
+ def log_id
44
+ "Node[#{@id}]"
45
+ end
46
+
47
+ # def processors_dup
48
+ # @processors.synchronize do
49
+ # @processors.dup
50
+ # end
51
+ # end
52
+
53
+ def start(master_host, master_port, service=0)
54
+ @deepconnect = DeepConnect.start(service)
55
+ @deepconnect.export("Node", self)
56
+
57
+ require "fairy/share/inspector"
58
+ @deepconnect.export("Inspector", Inspector.new(self))
59
+
60
+ require "fairy/share/log"
61
+ @master_deepspace = @deepconnect.open_deepspace(master_host, master_port)
62
+ @master = @master_deepspace.import("Master")
63
+ @logger = @master.logger
64
+ Log.type = "[N]"
65
+ Log.logger = @logger
66
+ Log.info(self, "Node Service Start")
67
+ Log::info(self, "\tfairy version: #{Version}")
68
+ Log::info(self, "\t[Powered BY #{RUBY_DESCRIPTION}]")
69
+
70
+ @master.register_node(self)
71
+ end
72
+
73
+ def processor_next_id
74
+ @processor_seq_mutex.synchronize do
75
+ @processor_seq += 1
76
+ end
77
+ end
78
+
79
+ def create_processor
80
+ proc = nil
81
+ @processors_mutex.synchronize do
82
+ processor_id = processor_next_id
83
+ # Process.spawn("test/testn.rb",
84
+ # "--controller", @deepconnect.local_id,
85
+ # "--id", processor_id.to_s)
86
+ # pid = Process.fork{
87
+ # Process.fork{
88
+ # exec(CONF.RUBY_BIN, CONF.PROCESSOR_BIN,
89
+ # "--node", @deepconnect.local_id.to_s,
90
+ # "--id", processor_id.to_s)
91
+ # }
92
+ # }
93
+ # Process.wait pid
94
+
95
+ pid = NodeAPP.start_subcommand2(CONF.RUBY_BIN,
96
+ CONF.PROCESSOR_BIN,
97
+ "--node", @deepconnect.local_id.to_s,
98
+ "--id", processor_id.to_s)
99
+ Process.wait pid
100
+
101
+ begin
102
+ timeout(CONF.SUBCMD_EXEC_TIMEOUT) do
103
+ while !@processors[processor_id]
104
+ @processors_cv.wait(@processors_mutex)
105
+ end
106
+ end
107
+ rescue Timeout::Error
108
+ Log::fatal(self, "Can't exec Processor")
109
+ ERR::Fail ERR::CantExecSubcmd, "processor"
110
+ end
111
+
112
+ @master.set_no_of_processors(self, @processors.size)
113
+ @processors[processor_id]
114
+ end
115
+ end
116
+
117
+ def terminate_processor(processor)
118
+ deregister_processor(processor)
119
+ begin
120
+ Log::info(self, "terminate processor.")
121
+ processor.terminate
122
+ rescue
123
+ Log::debug(self, "Exception Rised in termination processor.")
124
+ Log::debug_exception(self)
125
+ end
126
+ # forkの仕組みが変わった.
127
+ # Process.wait
128
+ end
129
+
130
+ def register_processor(processor)
131
+ # @processors.synchronize do
132
+ @processors_mutex.synchronize do
133
+ # ↓パフォーマンス悪い!!
134
+ @processors[processor.id] = processor
135
+ processor.addr = @addr
136
+
137
+ @processors_cv.broadcast
138
+ end
139
+ end
140
+
141
+ def deregister_processor(processor)
142
+ # @processors.synchronize do
143
+
144
+ update_processor_status(processor, :ST_WAIT)
145
+
146
+ @processors_mutex.synchronize do
147
+ # ↓パフォーマンス悪い!!
148
+ @processors.delete(processor.id)
149
+ @master.set_no_of_processors(self, @processors.size)
150
+
151
+ @processors_cv.broadcast
152
+ end
153
+ end
154
+
155
+ #
156
+ # process status management
157
+ #
158
+ def update_processor_status(processor, st)
159
+ Log::debug(self, "UPDATE_PROCESSOR_STATUS S: #{processor} #{st}")
160
+ @active_processors_mutex.synchronize do
161
+ case st
162
+ when :ST_WAIT, :ST_SEMIACTIVATE, :ST_FINISH
163
+ Log::debug(self, "UPDATE_PROCESSOR_STATUS: 2")
164
+ if @active_processors.key?(processor)
165
+ Log::debug(self, "UPDATE_PROCESSOR_STATUS: 3")
166
+ @active_processors.delete(processor)
167
+ @master.set_no_of_active_processors(self, @active_processors.size)
168
+ end
169
+ when :ST_ACTIVATE
170
+ Log::debug(self, "UPDATE_PROCESSOR_STATUS: 4")
171
+ @active_processors[processor] = processor
172
+ @master.set_no_of_active_processors(self, @active_processors.size)
173
+ end
174
+ end
175
+ Log::debug(self, "UPDATE_PROCESSOR_STATUS: E")
176
+ end
177
+
178
+ def to_s
179
+ "#<#{self.class}: #{id}>"
180
+ end
181
+
182
+ def Node.start(master_host, master_port)
183
+ node = Node.new
184
+ node.start(master_host, master_port)
185
+ end
186
+ end
187
+ end