drbqs 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/drbqs.gemspec +7 -2
- data/lib/drbqs/client.rb +35 -8
- data/lib/drbqs/connection.rb +5 -5
- data/lib/drbqs/history.rb +34 -0
- data/lib/drbqs/manage.rb +2 -2
- data/lib/drbqs/message.rb +14 -13
- data/lib/drbqs/node_list.rb +5 -23
- data/lib/drbqs/queue.rb +51 -12
- data/lib/drbqs/server.rb +33 -6
- data/lib/drbqs/server_define.rb +2 -0
- data/lib/drbqs/task_client.rb +15 -4
- data/spec/connection_spec.rb +4 -4
- data/spec/history_spec.rb +86 -0
- data/spec/message_spec.rb +4 -4
- data/spec/node_list_spec.rb +2 -28
- data/spec/queue_spec.rb +1 -1
- data/spec/server_check_alive_spec.rb +31 -0
- data/spec/task_client_spec.rb +1 -1
- metadata +8 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
data/drbqs.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{drbqs}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Takayuki YAMAGUCHI"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-25}
|
13
13
|
s.description = %q{Task queuing system over network that is implemented by dRuby.}
|
14
14
|
s.email = %q{d@ytak.info}
|
15
15
|
s.executables = ["drbqs-manage", "drbqs-node", "drbqs-server"]
|
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
"lib/drbqs/client.rb",
|
47
47
|
"lib/drbqs/config.rb",
|
48
48
|
"lib/drbqs/connection.rb",
|
49
|
+
"lib/drbqs/history.rb",
|
49
50
|
"lib/drbqs/manage.rb",
|
50
51
|
"lib/drbqs/message.rb",
|
51
52
|
"lib/drbqs/node_list.rb",
|
@@ -65,10 +66,12 @@ Gem::Specification.new do |s|
|
|
65
66
|
"spec/connection_spec.rb",
|
66
67
|
"spec/data/acl.txt",
|
67
68
|
"spec/filename_spec.rb",
|
69
|
+
"spec/history_spec.rb",
|
68
70
|
"spec/manage_spec.rb",
|
69
71
|
"spec/message_spec.rb",
|
70
72
|
"spec/node_list_spec.rb",
|
71
73
|
"spec/queue_spec.rb",
|
74
|
+
"spec/server_check_alive_spec.rb",
|
72
75
|
"spec/server_define_spec.rb",
|
73
76
|
"spec/server_hook_spec.rb",
|
74
77
|
"spec/server_spec.rb",
|
@@ -92,10 +95,12 @@ Gem::Specification.new do |s|
|
|
92
95
|
"spec/config_spec.rb",
|
93
96
|
"spec/connection_spec.rb",
|
94
97
|
"spec/filename_spec.rb",
|
98
|
+
"spec/history_spec.rb",
|
95
99
|
"spec/manage_spec.rb",
|
96
100
|
"spec/message_spec.rb",
|
97
101
|
"spec/node_list_spec.rb",
|
98
102
|
"spec/queue_spec.rb",
|
103
|
+
"spec/server_check_alive_spec.rb",
|
99
104
|
"spec/server_define_spec.rb",
|
100
105
|
"spec/server_hook_spec.rb",
|
101
106
|
"spec/server_spec.rb",
|
data/lib/drbqs/client.rb
CHANGED
@@ -6,6 +6,8 @@ module DRbQS
|
|
6
6
|
class Client
|
7
7
|
|
8
8
|
WAIT_NEW_TASK = 1
|
9
|
+
PRIORITY_RESPOND = 10
|
10
|
+
PRIORITY_CALCULATE = 0
|
9
11
|
OUTPUT_NOT_SEND_RESULT = 'not_send_result'
|
10
12
|
|
11
13
|
# :continue
|
@@ -70,15 +72,29 @@ module DRbQS
|
|
70
72
|
end
|
71
73
|
private :process_exit
|
72
74
|
|
73
|
-
def
|
74
|
-
|
75
|
+
def communicate_with_server
|
76
|
+
@task_client.add_new_task
|
77
|
+
if @connection.respond_signal == :exit
|
78
|
+
return nil
|
79
|
+
end
|
80
|
+
@task_client.send_result
|
81
|
+
return true
|
82
|
+
end
|
83
|
+
private :communicate_with_server
|
84
|
+
|
85
|
+
def calculate_task
|
86
|
+
marshal_obj, method_sym, args = @task_client.dequeue_task
|
87
|
+
@task_client.queue_result(execute_task(marshal_obj, method_sym, args))
|
88
|
+
end
|
89
|
+
private :calculate_task
|
90
|
+
|
91
|
+
def thread_communicate
|
92
|
+
Thread.new do
|
75
93
|
begin
|
76
94
|
loop do
|
77
|
-
|
78
|
-
if @connection.respond_alive_signal == :exit
|
95
|
+
unless communicate_with_server
|
79
96
|
break
|
80
97
|
end
|
81
|
-
@task_client.send_result
|
82
98
|
sleep(WAIT_NEW_TASK)
|
83
99
|
end
|
84
100
|
rescue => err
|
@@ -87,17 +103,28 @@ module DRbQS
|
|
87
103
|
process_exit
|
88
104
|
end
|
89
105
|
end
|
90
|
-
|
106
|
+
end
|
107
|
+
private :thread_communicate
|
108
|
+
|
109
|
+
def thread_calculate
|
110
|
+
Thread.new do
|
91
111
|
begin
|
92
112
|
loop do
|
93
|
-
|
94
|
-
@task_client.queue_result(execute_task(marshal_obj, method_sym, args))
|
113
|
+
calculate_task
|
95
114
|
end
|
96
115
|
rescue => err
|
97
116
|
output_error(err)
|
98
117
|
process_exit
|
99
118
|
end
|
100
119
|
end
|
120
|
+
end
|
121
|
+
private :thread_calculate
|
122
|
+
|
123
|
+
def calculate(opts = {})
|
124
|
+
cn = thread_communicate
|
125
|
+
exec = thread_calculate
|
126
|
+
cn.priority = PRIORITY_RESPOND
|
127
|
+
exec.priority = PRIORITY_CALCULATE
|
101
128
|
cn.join
|
102
129
|
end
|
103
130
|
end
|
data/lib/drbqs/connection.rb
CHANGED
@@ -12,13 +12,13 @@ module DRbQS
|
|
12
12
|
|
13
13
|
def create_id_string
|
14
14
|
t = Time.now
|
15
|
-
sprintf("
|
15
|
+
sprintf("#{Socket.gethostname}:%d", Process.pid)
|
16
16
|
end
|
17
17
|
private :create_id_string
|
18
18
|
|
19
19
|
def get_id
|
20
20
|
unless @id_number
|
21
|
-
@message.write([:connect, @id_string])
|
21
|
+
@message.write([:server, :connect, @id_string])
|
22
22
|
@id_number = @message.take([@id_string, Fixnum])[1]
|
23
23
|
@logger.info("Get node id: #{@id_number}") if @logger
|
24
24
|
end
|
@@ -34,15 +34,15 @@ module DRbQS
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def respond_signal
|
38
38
|
begin
|
39
39
|
node_id, sym = @message.take([@id_number, Symbol], 0)
|
40
|
+
@logger.info("Get signal: #{sym.inspect}") if @logger
|
40
41
|
case sym
|
41
42
|
when :alive_p
|
42
|
-
@message.write([:alive, @id_number])
|
43
|
+
@message.write([:server, :alive, @id_number])
|
43
44
|
@logger.info("Send alive signal of node id #{@id_number}") if @logger
|
44
45
|
when :exit
|
45
|
-
@logger.info("Get exit signal") if @logger
|
46
46
|
return :exit
|
47
47
|
end
|
48
48
|
rescue Rinda::RequestExpiredError
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module DRbQS
|
2
|
+
module HistoryUtils
|
3
|
+
def time_to_string(t)
|
4
|
+
t.strftime("%Y-%m-%d %H:%M:%S")
|
5
|
+
end
|
6
|
+
module_function :time_to_string
|
7
|
+
end
|
8
|
+
|
9
|
+
class History
|
10
|
+
def initialize
|
11
|
+
@data = Hash.new { |h, k| h[k] = Array.new }
|
12
|
+
end
|
13
|
+
|
14
|
+
def set(id, *args)
|
15
|
+
@data[id] << [Time.now] + args
|
16
|
+
end
|
17
|
+
|
18
|
+
def size
|
19
|
+
@data.size
|
20
|
+
end
|
21
|
+
|
22
|
+
def events(id)
|
23
|
+
@data[id]
|
24
|
+
end
|
25
|
+
|
26
|
+
def number_of_events(id)
|
27
|
+
@data[id].size
|
28
|
+
end
|
29
|
+
|
30
|
+
def each(&block)
|
31
|
+
@data.each(&block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/drbqs/manage.rb
CHANGED
@@ -15,11 +15,11 @@ module DRbQS
|
|
15
15
|
private :get_hostname
|
16
16
|
|
17
17
|
def send_exit_signal
|
18
|
-
@message.write([:exit_server, get_hostname])
|
18
|
+
@message.write([:server, :exit_server, get_hostname])
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_status
|
22
|
-
@message.write([:request_status, get_hostname])
|
22
|
+
@message.write([:server, :request_status, get_hostname])
|
23
23
|
i = 0
|
24
24
|
loop do
|
25
25
|
begin
|
data/lib/drbqs/message.rb
CHANGED
@@ -2,6 +2,8 @@ require 'drbqs/node_list'
|
|
2
2
|
|
3
3
|
module DRbQS
|
4
4
|
class MessageServer
|
5
|
+
include HistoryUtils
|
6
|
+
|
5
7
|
def initialize(message, logger = nil)
|
6
8
|
@message = message
|
7
9
|
@node_list = NodeList.new
|
@@ -10,8 +12,8 @@ module DRbQS
|
|
10
12
|
|
11
13
|
def get_message
|
12
14
|
begin
|
13
|
-
mes = @message.take([Symbol, nil], 0)
|
14
|
-
manage_message(*mes)
|
15
|
+
mes = @message.take([:server, Symbol, nil], 0)
|
16
|
+
manage_message(*mes[1..2])
|
15
17
|
rescue Rinda::RequestExpiredError
|
16
18
|
nil
|
17
19
|
end
|
@@ -40,7 +42,7 @@ module DRbQS
|
|
40
42
|
|
41
43
|
def check_connection
|
42
44
|
deleted = @node_list.delete_not_alive
|
43
|
-
@logger.info("IDs of deleted nodes") { deleted } if @logger
|
45
|
+
@logger.info("IDs of deleted nodes") { deleted } if deleted.size > 0 && @logger
|
44
46
|
@node_list.each do |id, str|
|
45
47
|
@message.write([id, :alive_p])
|
46
48
|
end
|
@@ -54,20 +56,19 @@ module DRbQS
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
def time_to_string(t)
|
58
|
-
t.strftime("%Y-%m-%d %H:%M:%S")
|
59
|
-
end
|
60
|
-
private :time_to_string
|
61
|
-
|
62
59
|
def send_status(calculating_task_id)
|
63
60
|
s = ''
|
64
|
-
@node_list.history.each do |node_id,
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
@node_list.history.each do |node_id, events|
|
62
|
+
if events.size == 0 || events.size > 2
|
63
|
+
raise "Invalid history of nodes: #{events.inspect}"
|
64
|
+
end
|
65
|
+
connect = events[0]
|
66
|
+
s << sprintf("%4d %s\t", node_id, connect[2])
|
67
|
+
if disconnect = events[1]
|
68
|
+
s << "disconnected: (#{time_to_string(connect[0])} - #{time_to_string(disconnect[0])})\n"
|
68
69
|
else
|
69
70
|
task_ids = calculating_task_id[node_id]
|
70
|
-
s << "task: #{task_ids.map { |num| num.to_s }.join(', ')} (#{time_to_string(
|
71
|
+
s << "task: #{task_ids.map { |num| num.to_s }.join(', ')} (#{time_to_string(connect[0])})\n"
|
71
72
|
end
|
72
73
|
end
|
73
74
|
begin
|
data/lib/drbqs/node_list.rb
CHANGED
@@ -1,24 +1,6 @@
|
|
1
|
-
|
2
|
-
class NodeHistory
|
3
|
-
def initialize
|
4
|
-
@data = {}
|
5
|
-
end
|
6
|
-
|
7
|
-
def add(id, id_str)
|
8
|
-
@data[id] = [id_str, Time.now]
|
9
|
-
end
|
10
|
-
|
11
|
-
def disconnect(id)
|
12
|
-
if @data[id]
|
13
|
-
@data[id] << Time.now
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def each(&block)
|
18
|
-
@data.each(&block)
|
19
|
-
end
|
20
|
-
end
|
1
|
+
require 'drbqs/history'
|
21
2
|
|
3
|
+
module DRbQS
|
22
4
|
class NodeList
|
23
5
|
attr_reader :history
|
24
6
|
|
@@ -26,13 +8,13 @@ module DRbQS
|
|
26
8
|
@id = 0
|
27
9
|
@list = {}
|
28
10
|
@check = []
|
29
|
-
@history =
|
11
|
+
@history = History.new
|
30
12
|
end
|
31
13
|
|
32
14
|
def get_new_id(id_str)
|
33
15
|
@id += 1
|
34
16
|
@list[@id] = id_str
|
35
|
-
@history.
|
17
|
+
@history.set(@id, :connect, @list[@id])
|
36
18
|
@id
|
37
19
|
end
|
38
20
|
|
@@ -47,7 +29,7 @@ module DRbQS
|
|
47
29
|
def delete_not_alive
|
48
30
|
@check.each do |id|
|
49
31
|
@list.delete(id)
|
50
|
-
@history.
|
32
|
+
@history.set(id, :disconnect)
|
51
33
|
end
|
52
34
|
deleted = @check
|
53
35
|
@check = []
|
data/lib/drbqs/queue.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'drbqs/history'
|
2
|
+
|
1
3
|
module DRbQS
|
2
4
|
|
3
5
|
class QueueServer
|
4
|
-
|
6
|
+
include HistoryUtils
|
7
|
+
|
8
|
+
attr_reader :calculating, :history
|
5
9
|
|
6
10
|
def initialize(queue, result, logger = nil)
|
7
11
|
@queue = queue
|
@@ -9,6 +13,7 @@ module DRbQS
|
|
9
13
|
@task_id = 0
|
10
14
|
@cache = {}
|
11
15
|
@calculating = Hash.new { |hash, key| hash[key] = Array.new }
|
16
|
+
@history = DRbQS::History.new
|
12
17
|
@logger = logger
|
13
18
|
end
|
14
19
|
|
@@ -24,6 +29,7 @@ module DRbQS
|
|
24
29
|
@logger.info("New task: #{@task_id}") if @logger
|
25
30
|
@cache[@task_id] = task
|
26
31
|
queue_task(@task_id)
|
32
|
+
@history.set(@task_id, :add)
|
27
33
|
@task_id
|
28
34
|
end
|
29
35
|
|
@@ -34,6 +40,7 @@ module DRbQS
|
|
34
40
|
sym, task_id, node_id = @result.take([:accept, Fixnum, Fixnum], 0)
|
35
41
|
count += 1
|
36
42
|
@calculating[node_id] << task_id
|
43
|
+
@history.set(task_id, :calculate, node_id)
|
37
44
|
@logger.info("Accept: task #{task_id} by node #{node_id}.") if @logger
|
38
45
|
end
|
39
46
|
rescue Rinda::RequestExpiredError
|
@@ -47,6 +54,7 @@ module DRbQS
|
|
47
54
|
if task_id_ary = @calculating[node_id]
|
48
55
|
task_id_ary.each do |task_id|
|
49
56
|
queue_task(task_id)
|
57
|
+
@history.set(task_id, :requeue)
|
50
58
|
@logger.info("Requeue: task #{task_id}.") if @logger
|
51
59
|
end
|
52
60
|
@calculating.delete(node_id)
|
@@ -54,24 +62,39 @@ module DRbQS
|
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
65
|
+
def delete_task_id(node_id, task_id)
|
66
|
+
unless @calculating[node_id].delete(task_id)
|
67
|
+
@logger.error("Task #{task_id} does not exist in list of calculating tasks.") if @logger
|
68
|
+
end
|
69
|
+
if ary = @calculating.find { |k, v| v.include?(task_id) }
|
70
|
+
@logger.error("Node #{ary[0]} is calculating task #{task_id}, too.") if @logger
|
71
|
+
end
|
72
|
+
end
|
73
|
+
private :delete_task_id
|
74
|
+
|
75
|
+
def exec_task_hook(task_id, result)
|
76
|
+
if task = @cache.delete(task_id)
|
77
|
+
if hook = task.hook
|
78
|
+
@history.set(task_id, :hook)
|
79
|
+
hook.call(self, result)
|
80
|
+
end
|
81
|
+
else
|
82
|
+
@logger.error("Task #{task_id} is not cached.") if @logger
|
83
|
+
end
|
84
|
+
end
|
85
|
+
private :exec_task_hook
|
86
|
+
|
57
87
|
def get_result
|
58
88
|
count = 0
|
59
89
|
begin
|
60
90
|
loop do
|
61
91
|
get_accept_signal
|
62
|
-
sym, task_id, result = @result.take([:result, Fixnum, nil], 0)
|
92
|
+
sym, task_id, node_id, result = @result.take([:result, Fixnum, Fixnum, nil], 0)
|
63
93
|
count += 1
|
64
|
-
|
65
|
-
node_id = ary[0]
|
66
|
-
@calculating[node_id].delete(task_id)
|
67
|
-
else
|
68
|
-
node_id = nil
|
69
|
-
end
|
94
|
+
@history.set(task_id, :result, node_id)
|
70
95
|
@logger.info("Get: result of #{task_id} from node #{node_id}.") if @logger
|
71
|
-
|
72
|
-
|
73
|
-
hook.call(self, result)
|
74
|
-
end
|
96
|
+
delete_task_id(node_id, task_id)
|
97
|
+
exec_task_hook(task_id, result)
|
75
98
|
end
|
76
99
|
rescue Rinda::RequestExpiredError
|
77
100
|
@logger.debug("Get: #{count} results.") if @logger
|
@@ -95,6 +118,22 @@ module DRbQS
|
|
95
118
|
def finished?
|
96
119
|
@cache.size == 0
|
97
120
|
end
|
121
|
+
|
122
|
+
def all_logs
|
123
|
+
s = ''
|
124
|
+
@history.each do |task_id, events|
|
125
|
+
s << "Task #{task_id}\n"
|
126
|
+
events.each do |ev|
|
127
|
+
case ev[1]
|
128
|
+
when :add, :requeue, :hook
|
129
|
+
s << " #{time_to_string(ev[0])}\t#{ev[1]}\n"
|
130
|
+
when :calculate, :result
|
131
|
+
s << " #{time_to_string(ev[0])}\t#{ev[1]} (node #{ev[2]})\n"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
s
|
136
|
+
end
|
98
137
|
end
|
99
138
|
|
100
139
|
end
|
data/lib/drbqs/server.rb
CHANGED
@@ -9,6 +9,9 @@ module DRbQS
|
|
9
9
|
|
10
10
|
def initialize(interval)
|
11
11
|
@interval = interval || DEFAULT_INTERVAL_TIME
|
12
|
+
if !(Numeric === @interval) || @interval < 0
|
13
|
+
raise ArgumentError, "Invalid interval time."
|
14
|
+
end
|
12
15
|
@last = Time.now
|
13
16
|
end
|
14
17
|
|
@@ -93,7 +96,7 @@ module DRbQS
|
|
93
96
|
|
94
97
|
def check_connection(force = nil)
|
95
98
|
if force || @check_alive.significant_interval?
|
96
|
-
@logger.
|
99
|
+
@logger.info("Check connections.") if @logger
|
97
100
|
deleted_node_ids = @message.check_connection
|
98
101
|
@queue.requeue_for_deleted_node_id(deleted_node_ids)
|
99
102
|
@check_alive.set_checking
|
@@ -154,6 +157,7 @@ module DRbQS
|
|
154
157
|
sleep(WAIT_TIME_NODE_EXIT)
|
155
158
|
check_connection(true)
|
156
159
|
end
|
160
|
+
@logger.info("History of tasks") { "\n" + @queue.all_logs } if @logger
|
157
161
|
Kernel.exit
|
158
162
|
end
|
159
163
|
|
@@ -168,11 +172,13 @@ module DRbQS
|
|
168
172
|
end
|
169
173
|
|
170
174
|
def check_message
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
175
|
+
while mes = @message.get_message
|
176
|
+
case mes
|
177
|
+
when :exit_server
|
178
|
+
self.exit
|
179
|
+
when :request_status
|
180
|
+
@message.send_status(@queue.calculating)
|
181
|
+
end
|
176
182
|
end
|
177
183
|
end
|
178
184
|
private :check_message
|
@@ -196,6 +202,27 @@ module DRbQS
|
|
196
202
|
end
|
197
203
|
end
|
198
204
|
|
205
|
+
def test_exec(opts = {})
|
206
|
+
task_generator_init
|
207
|
+
dummy_client = DRbQS::Client.new(nil, :log_file => $stdout, :log_level => opts[:log_level])
|
208
|
+
dummy_task_client = DRbQS::TaskClient.new(nil, @ts[:queue], nil)
|
209
|
+
num = 0
|
210
|
+
loop do
|
211
|
+
num += 1
|
212
|
+
exec_hook
|
213
|
+
if ary = dummy_task_client.get_task
|
214
|
+
task_id, marshal_obj, method_sym, args = ary
|
215
|
+
result = dummy_client.instance_eval { execute_task(marshal_obj, method_sym, args) }
|
216
|
+
@queue.instance_eval do
|
217
|
+
exec_task_hook(task_id, result)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
if opts[:limit] && num > opts[:limit]
|
221
|
+
break
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
199
226
|
def test_task_generator(opts = {})
|
200
227
|
task_generator_init
|
201
228
|
@task_generator.each_with_index do |t, i|
|
data/lib/drbqs/server_define.rb
CHANGED
@@ -63,6 +63,8 @@ HELP
|
|
63
63
|
when :task
|
64
64
|
puts "*** Test of Task Generators ***"
|
65
65
|
server.test_task_generator(:limit => arg[0] ? arg[0].to_i : nil, :progress => true)
|
66
|
+
when :exec
|
67
|
+
server.test_exec(:limit => arg[0] ? arg[0].to_i : nil)
|
66
68
|
else
|
67
69
|
puts "*** Not be yet implemented ***"
|
68
70
|
end
|
data/lib/drbqs/task_client.rb
CHANGED
@@ -12,6 +12,10 @@ module DRbQS
|
|
12
12
|
@logger = logger
|
13
13
|
end
|
14
14
|
|
15
|
+
def calculating?
|
16
|
+
!!@calculating_task
|
17
|
+
end
|
18
|
+
|
15
19
|
def task_empty?
|
16
20
|
@task_queue.empty?
|
17
21
|
end
|
@@ -34,14 +38,21 @@ module DRbQS
|
|
34
38
|
@task_queue.deq
|
35
39
|
end
|
36
40
|
|
41
|
+
def get_task
|
42
|
+
begin
|
43
|
+
@queue.take([Fixnum, nil, Symbol, nil], 0)
|
44
|
+
rescue Rinda::RequestExpiredError
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
37
49
|
def add_new_task
|
38
50
|
unless @calculating_task
|
39
|
-
|
40
|
-
task_id, obj, method_sym, args =
|
51
|
+
if ary = get_task
|
52
|
+
task_id, obj, method_sym, args = ary
|
41
53
|
queue_task(task_id, [obj, method_sym, args])
|
42
54
|
@logger.info("Send accept signal: node #{@node_id} caluclating #{@calculating_task}") if @logger
|
43
55
|
@result.write([:accept, @calculating_task, @node_id])
|
44
|
-
rescue Rinda::RequestExpiredError
|
45
56
|
end
|
46
57
|
end
|
47
58
|
end
|
@@ -50,7 +61,7 @@ module DRbQS
|
|
50
61
|
if !result_empty?
|
51
62
|
result = dequeue_result
|
52
63
|
@logger.info("Send result: #{@calculating_task}") { result.inspect } if @logger
|
53
|
-
@result.write([:result, @calculating_task, result])
|
64
|
+
@result.write([:result, @calculating_task, @node_id, result])
|
54
65
|
@calculating_task = nil
|
55
66
|
end
|
56
67
|
end
|
data/spec/connection_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe DRbQS::ConnectionClient do
|
|
13
13
|
|
14
14
|
it "should get node ID." do
|
15
15
|
@connection.get_id.should == @node_id
|
16
|
-
@message.take([:connect, nil]).should be_true
|
16
|
+
@message.take([:server, :connect, nil], 0).should be_true
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should get no initialization method." do
|
@@ -28,12 +28,12 @@ describe DRbQS::ConnectionClient do
|
|
28
28
|
|
29
29
|
it "should respond :alive_p signal" do
|
30
30
|
@message.write([@node_id, :alive_p])
|
31
|
-
@connection.
|
32
|
-
@message.take([:alive, nil]).should be_true
|
31
|
+
@connection.respond_signal
|
32
|
+
@message.take([:server, :alive, nil], 0).should be_true
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should respond :exit signal" do
|
36
36
|
@message.write([@node_id, :exit])
|
37
|
-
@connection.
|
37
|
+
@connection.respond_signal.should == :exit
|
38
38
|
end
|
39
39
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/history'
|
4
|
+
|
5
|
+
describe DRbQS::History do
|
6
|
+
|
7
|
+
def check_event(event, *vals)
|
8
|
+
event[0].should be_an_instance_of Time
|
9
|
+
event[1..-1].each_with_index do |obj, i|
|
10
|
+
obj.should == vals[i]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when setting events" do
|
15
|
+
before(:all) do
|
16
|
+
@history = DRbQS::History.new
|
17
|
+
@history.set(1, :abc)
|
18
|
+
@history.set(1, :def)
|
19
|
+
@history.set(2, 'ABC', 'DEF')
|
20
|
+
@history.set(3, :ghi)
|
21
|
+
@history.set(1, :jkl)
|
22
|
+
@history.set(2, 123, 456)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have 3 items." do
|
26
|
+
@history.should have(3).items
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should 3 events of ID 1." do
|
30
|
+
@history.number_of_events(1).should == 3
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should 2 events of ID 2" do
|
34
|
+
@history.number_of_events(2).should == 2
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should 1 event of ID 3" do
|
38
|
+
@history.number_of_events(3).should == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should check events of ID 1" do
|
42
|
+
events = @history.events(1)
|
43
|
+
check_event(events[0], :abc)
|
44
|
+
check_event(events[1], :def)
|
45
|
+
check_event(events[2], :jkl)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should check events of ID 2" do
|
49
|
+
events = @history.events(2)
|
50
|
+
check_event(events[0], 'ABC', 'DEF')
|
51
|
+
check_event(events[1], 123, 456)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should check events of ID 1" do
|
55
|
+
events = @history.events(3)
|
56
|
+
check_event(events[0], :ghi)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when executing a method" do
|
61
|
+
subject { DRbQS::History.new }
|
62
|
+
|
63
|
+
it "should add new event" do
|
64
|
+
id = 1
|
65
|
+
subject.set(id, :connect)
|
66
|
+
subject.should have(1).items
|
67
|
+
subject.number_of_events(id).should == 1
|
68
|
+
check_event(subject.events(1)[0], :connect)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should execute each events" do
|
72
|
+
subject.set(3, '100', '200')
|
73
|
+
subject.set(3, '300', '400')
|
74
|
+
subject.set(4, 500, 600, 700)
|
75
|
+
subject.each do |id, events|
|
76
|
+
case id
|
77
|
+
when 3
|
78
|
+
check_event(events[0], '100', '200')
|
79
|
+
check_event(events[1], '300', '400')
|
80
|
+
when 4
|
81
|
+
check_event(events[0], 500, 600, 700)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/spec/message_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe DRbQS::MessageServer do
|
|
28
28
|
it "should get :connect message" do
|
29
29
|
5.times do |i|
|
30
30
|
id_str = "connect_test_#{i}"
|
31
|
-
@message.write([:connect, id_str])
|
31
|
+
@message.write([:server, :connect, id_str])
|
32
32
|
@message_server.get_message
|
33
33
|
(ary = @message.take([id_str, Fixnum])).should be_true
|
34
34
|
@node_id_list << ary[1]
|
@@ -38,14 +38,14 @@ describe DRbQS::MessageServer do
|
|
38
38
|
|
39
39
|
it "should get :alive message" do
|
40
40
|
node_id = 73
|
41
|
-
@message.write([:alive, node_id])
|
41
|
+
@message.write([:server, :alive, node_id])
|
42
42
|
node_list = @message_server.instance_variable_get(:@node_list)
|
43
43
|
node_list.should_receive(:set_alive).with(node_id)
|
44
44
|
@message_server.get_message
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should get :exit_server message" do
|
48
|
-
@message.write([:exit_server, 'message_test'])
|
48
|
+
@message.write([:server, :exit_server, 'message_test'])
|
49
49
|
@message_server.get_message.should == :exit_server
|
50
50
|
end
|
51
51
|
|
@@ -70,7 +70,7 @@ describe DRbQS::MessageServer do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should get :request_status message" do
|
73
|
-
@message.write([:request_status, 'message_test'])
|
73
|
+
@message.write([:server, :request_status, 'message_test'])
|
74
74
|
@message_server.get_message.should == :request_status
|
75
75
|
end
|
76
76
|
|
data/spec/node_list_spec.rb
CHANGED
@@ -2,32 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
require 'drbqs/node_list'
|
4
4
|
|
5
|
-
describe DRbQS::NodeHistory do
|
6
|
-
subject { DRbQS::NodeHistory.new }
|
7
|
-
|
8
|
-
it "should add new id" do
|
9
|
-
subject.add(1, 'hello')
|
10
|
-
ary = subject.each.to_a
|
11
|
-
ary.should have(1).items
|
12
|
-
ary[0][0].should == 1
|
13
|
-
ary[0][1].should have(2).items
|
14
|
-
ary[0][1][0].should == 'hello'
|
15
|
-
ary[0][1][1].should be_an_instance_of Time
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should set disconnected" do
|
19
|
-
subject.add(1, 'hello')
|
20
|
-
subject.disconnect(1)
|
21
|
-
ary = subject.each.to_a
|
22
|
-
ary.should have(1).items
|
23
|
-
ary[0][0].should == 1
|
24
|
-
ary[0][1].should have(3).items
|
25
|
-
ary[0][1][0].should == 'hello'
|
26
|
-
ary[0][1][1].should be_an_instance_of Time
|
27
|
-
ary[0][1][2].should be_an_instance_of Time
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
5
|
describe DRbQS::NodeList do
|
32
6
|
before(:all) do
|
33
7
|
@node_list = DRbQS::NodeList.new
|
@@ -79,15 +53,15 @@ describe DRbQS::NodeList do
|
|
79
53
|
|
80
54
|
it "should add to history" do
|
81
55
|
node_list = DRbQS::NodeList.new
|
82
|
-
node_list.history.should_receive(:
|
56
|
+
node_list.history.should_receive(:set).with(1, :connect, 'hello')
|
83
57
|
node_list.get_new_id('hello')
|
84
58
|
end
|
85
59
|
|
86
60
|
it "should set disconnection to history" do
|
87
61
|
node_list = DRbQS::NodeList.new
|
88
|
-
node_list.history.should_receive(:disconnect)
|
89
62
|
node_list.get_new_id('hello')
|
90
63
|
node_list.set_check_connection
|
64
|
+
node_list.history.should_receive(:set).with(1, :disconnect)
|
91
65
|
node_list.delete_not_alive
|
92
66
|
end
|
93
67
|
|
data/spec/queue_spec.rb
CHANGED
@@ -37,7 +37,7 @@ describe DRbQS::QueueServer do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should get result" do
|
40
|
-
@ts[:result].write([:result, @task[:id], :result_object])
|
40
|
+
@ts[:result].write([:result, @task[:id], @node_id, :result_object])
|
41
41
|
@queue_server.get_result
|
42
42
|
@queue_server.calculating_task_number.should == 0
|
43
43
|
@queue_server.empty?.should be_true
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/server'
|
4
|
+
|
5
|
+
describe DRbQS::CheckAlive do
|
6
|
+
it "should raise error with not a number" do
|
7
|
+
lambda do
|
8
|
+
DRbQS::CheckAlive.new('abc')
|
9
|
+
end.should raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise error with a minus number" do
|
13
|
+
lambda do
|
14
|
+
DRbQS::CheckAlive.new(-10)
|
15
|
+
end.should raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return true" do
|
19
|
+
check = DRbQS::CheckAlive.new(0.1)
|
20
|
+
sleep(0.3)
|
21
|
+
check.significant_interval?.should be_true
|
22
|
+
check.set_checking
|
23
|
+
sleep(0.01)
|
24
|
+
check.significant_interval?.should be_false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return false" do
|
28
|
+
check = DRbQS::CheckAlive.new(100)
|
29
|
+
check.significant_interval?.should be_false
|
30
|
+
end
|
31
|
+
end
|
data/spec/task_client_spec.rb
CHANGED
@@ -48,6 +48,6 @@ describe DRbQS::TaskClient do
|
|
48
48
|
@task_client.task_empty?.should be_true
|
49
49
|
@task_client.result_empty?.should be_true
|
50
50
|
@task_client.calculating_task.should be_nil
|
51
|
-
@ts_result.take([:result, nil, nil], 0).should be_true
|
51
|
+
@ts_result.take([:result, nil, nil, nil], 0).should be_true
|
52
52
|
end
|
53
53
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: drbqs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Takayuki YAMAGUCHI
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-25 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/drbqs/client.rb
|
142
142
|
- lib/drbqs/config.rb
|
143
143
|
- lib/drbqs/connection.rb
|
144
|
+
- lib/drbqs/history.rb
|
144
145
|
- lib/drbqs/manage.rb
|
145
146
|
- lib/drbqs/message.rb
|
146
147
|
- lib/drbqs/node_list.rb
|
@@ -160,10 +161,12 @@ files:
|
|
160
161
|
- spec/connection_spec.rb
|
161
162
|
- spec/data/acl.txt
|
162
163
|
- spec/filename_spec.rb
|
164
|
+
- spec/history_spec.rb
|
163
165
|
- spec/manage_spec.rb
|
164
166
|
- spec/message_spec.rb
|
165
167
|
- spec/node_list_spec.rb
|
166
168
|
- spec/queue_spec.rb
|
169
|
+
- spec/server_check_alive_spec.rb
|
167
170
|
- spec/server_define_spec.rb
|
168
171
|
- spec/server_hook_spec.rb
|
169
172
|
- spec/server_spec.rb
|
@@ -190,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
193
|
requirements:
|
191
194
|
- - ">="
|
192
195
|
- !ruby/object:Gem::Version
|
193
|
-
hash:
|
196
|
+
hash: 4286900576171591504
|
194
197
|
segments:
|
195
198
|
- 0
|
196
199
|
version: "0"
|
@@ -212,10 +215,12 @@ test_files:
|
|
212
215
|
- spec/config_spec.rb
|
213
216
|
- spec/connection_spec.rb
|
214
217
|
- spec/filename_spec.rb
|
218
|
+
- spec/history_spec.rb
|
215
219
|
- spec/manage_spec.rb
|
216
220
|
- spec/message_spec.rb
|
217
221
|
- spec/node_list_spec.rb
|
218
222
|
- spec/queue_spec.rb
|
223
|
+
- spec/server_check_alive_spec.rb
|
219
224
|
- spec/server_define_spec.rb
|
220
225
|
- spec/server_hook_spec.rb
|
221
226
|
- spec/server_spec.rb
|