abundance 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/abundance.rb +11 -5
- data/lib/garden.rb +5 -5
- data/lib/garden_cycles.rb +14 -4
- data/lib/gardener.rb +1 -1
- data/lib/rows.rb +38 -35
- data/lib/rows_paths.rb +6 -1
- data/lib/seed.rb +1 -0
- data/test/tc_burst.rb +6 -2
- data/test/tc_high_api.rb +14 -5
- data/test/tc_multi_gardener.rb +8 -2
- data/test/tc_queue.rb +5 -2
- data/test/tc_robustness.rb +8 -2
- data/test/ts_abundance.rb +5 -7
- metadata +13 -4
data/lib/abundance.rb
CHANGED
@@ -37,11 +37,13 @@
|
|
37
37
|
# Copyright:: 2008 Louis-Philippe Perron - Released under the terms of the MIT license
|
38
38
|
#
|
39
39
|
# :title:Abundance
|
40
|
+
require 'globalog'
|
41
|
+
$log_abundance = GlobaLog.logger(STDERR,:warn)
|
40
42
|
|
41
43
|
class Abundance
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'garden')
|
45
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'gardener')
|
46
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'seed')
|
45
47
|
|
46
48
|
# The +gardener+ class method initializes a gardener instance
|
47
49
|
# with its garden supplied as a block. The invocation block must include
|
@@ -79,15 +81,18 @@ class Abundance
|
|
79
81
|
# gardener.close
|
80
82
|
|
81
83
|
def Abundance.gardener(options={:wheelbarrow => 8192, :rows => 2, :init_timeout => 2},&gardener_block)
|
82
|
-
|
84
|
+
$log_abundance.debug("Abundance.gardener") {"options: #{options.inspect}"}
|
85
|
+
return Gardener.new(options,gardener_block)
|
83
86
|
end
|
84
87
|
|
85
88
|
# The +grow+ class method needs to be used inside the gardener invocation.
|
86
89
|
# A seed instance is given each time, acting as getter/setter for your queued seed commands
|
87
90
|
|
88
91
|
def Abundance.grow(&grow_block)
|
89
|
-
|
92
|
+
until nil
|
93
|
+
$log_abundance.debug("Abundance.grow") {"enter loop"}
|
90
94
|
unless $seed.nil? || $seed.include?(:message)
|
95
|
+
$log_abundance.debug("Abundance.grow") {"call grow block for seed: #{$seed.inspect}"}
|
91
96
|
grow_block.call(Seed.new)
|
92
97
|
end
|
93
98
|
Thread.stop
|
@@ -102,6 +107,7 @@ class Abundance
|
|
102
107
|
# === Example
|
103
108
|
# Abundance.init_status(true,'Initialisation Successfull!!!')
|
104
109
|
def Abundance.init_status(success,message)
|
110
|
+
$log_abundance.debug("Abundance.init_status") { "success: #{success.inspect} message: #{message.inspect}"}
|
105
111
|
$init = {:id => Process.pid, :seed => 'init_status', :success => success, :message => message}
|
106
112
|
end
|
107
113
|
|
data/lib/garden.rb
CHANGED
@@ -15,10 +15,10 @@
|
|
15
15
|
# :title:Garden
|
16
16
|
|
17
17
|
class Garden
|
18
|
-
|
19
|
-
|
18
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'rows')
|
19
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'garden_cycles')
|
20
20
|
include Cycles
|
21
|
-
|
21
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'toolshed')
|
22
22
|
include Toolshed
|
23
23
|
|
24
24
|
attr_reader :pid
|
@@ -37,10 +37,10 @@ class Garden
|
|
37
37
|
set_my_containers
|
38
38
|
set_my_socket_as_a(:garden)
|
39
39
|
|
40
|
-
|
40
|
+
until nil
|
41
41
|
route_message_blocks
|
42
42
|
seed_available_rows
|
43
|
-
|
43
|
+
$log_abundance.debug('garden') {"select reader: #{@reader[:sockets].inspect} writer: #{@writer[:sockets]}"}
|
44
44
|
ready = select(@reader[:sockets],@writer[:sockets],nil,10)
|
45
45
|
unless ready.nil?
|
46
46
|
readable, writable = ready[0..1]
|
data/lib/garden_cycles.rb
CHANGED
@@ -15,6 +15,7 @@ class Garden
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def sprout_readable(readable)
|
18
|
+
$log_abundance.debug('Garden::Cycles') {"sprout_readable"}
|
18
19
|
readable.each do |i_socket|
|
19
20
|
if i_socket == @my_socket
|
20
21
|
add_readable(i_socket)
|
@@ -25,6 +26,7 @@ class Garden
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def crop_writable(writable)
|
29
|
+
$log_abundance.debug('Garden::Cycles') {"crop_writable"}
|
28
30
|
writable.each do |o_socket|
|
29
31
|
if @writer[:buffer][o_socket.to_s] == '' || @writer[:buffer][o_socket.to_s] == nil
|
30
32
|
remove_writable(o_socket)
|
@@ -35,6 +37,7 @@ class Garden
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def route_message_blocks
|
40
|
+
$log_abundance.debug('Garden::Cycles') {"route_message_blocks"}
|
38
41
|
until @message_block_queue.empty?
|
39
42
|
message_block = @message_block_queue.shift
|
40
43
|
|
@@ -60,12 +63,15 @@ class Garden
|
|
60
63
|
end
|
61
64
|
|
62
65
|
def seed_available_rows
|
66
|
+
$log_abundance.debug('Garden::Cycles') {"seed_available_rows"}
|
63
67
|
catch :fill_rows do
|
64
|
-
|
68
|
+
looped = 0
|
69
|
+
while (looped+=1) < 9
|
65
70
|
throw :fill_rows if @waiting_rows.empty?
|
66
|
-
|
71
|
+
$log_abundance.debug('Garden::Cycles') {"seed_available_rows: waiting_rows: #{@waiting_rows.inspect}"}
|
67
72
|
if @seed_all_message_block && @seed_all_message_block[4][:row_done].size != @seed_all_message_block[1]
|
68
|
-
|
73
|
+
$log_abundance.debug('Garden::Cycles') {"seed_available_rows: all_message_block #{@seed_all_message_block.inspect}"}
|
74
|
+
row_socket_path = @waiting_rows.shift
|
69
75
|
unless @seed_all_message_block[4][:row_done].include?( row_socket_path )
|
70
76
|
add_writable([:seed,:all,@seed_all_message_block[2],row_socket_path])
|
71
77
|
@seed_all_message_block[4][:row_done] << row_socket_path
|
@@ -74,7 +80,8 @@ class Garden
|
|
74
80
|
end
|
75
81
|
|
76
82
|
elsif @init_message_block && @init_message_block[4][:row_done].size != @init_message_block[2]
|
77
|
-
|
83
|
+
$log_abundance.debug('Garden::Cycles') {"seed_available_rows: init_message_block #{@init_message_block.inspect}"}
|
84
|
+
row_socket_path = @waiting_rows.shift
|
78
85
|
unless @init_message_block[4][:row_done].include?( row_socket_path )
|
79
86
|
add_writable([:seed,:init,'init_status',row_socket_path])
|
80
87
|
@init_message_block[4][:row_done] << row_socket_path
|
@@ -83,13 +90,16 @@ class Garden
|
|
83
90
|
end
|
84
91
|
|
85
92
|
elsif ! @seeds.empty?
|
93
|
+
$log_abundance.debug('Garden::Cycles') {"seed_available_rows: ! seeds.empty? #{@seeds.inspect}"}
|
86
94
|
seed = @seeds.shift; @sprouts[seed[:id]] = seed
|
87
95
|
add_writable([:seed,:sprout,seed,@waiting_rows.shift])
|
88
96
|
|
89
97
|
elsif @close_message_block && ! @waiting_rows.empty?
|
98
|
+
$log_abundance.debug('Garden::Cycles') {"seed_available_rows: close_message_block: #{@close_message_block.inspect}"}
|
90
99
|
add_writable([:seed,:quit,nil,@waiting_rows.shift])
|
91
100
|
|
92
101
|
else
|
102
|
+
$log_abundance.debug('Garden::Cycles') {"seed_available_rows: else"}
|
93
103
|
throw :fill_rows
|
94
104
|
end
|
95
105
|
|
data/lib/gardener.rb
CHANGED
data/lib/rows.rb
CHANGED
@@ -20,9 +20,9 @@ class Garden
|
|
20
20
|
# :title:Rows
|
21
21
|
|
22
22
|
class Rows
|
23
|
-
|
23
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'rows_paths')
|
24
24
|
include Paths
|
25
|
-
|
25
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'toolshed')
|
26
26
|
include Toolshed
|
27
27
|
attr_reader :pids
|
28
28
|
|
@@ -45,41 +45,44 @@ class Garden
|
|
45
45
|
rows.times do
|
46
46
|
@pids << fork do
|
47
47
|
set_my_socket_as_a(:row,garden_pid)
|
48
|
-
t1 = Thread.new do
|
49
|
-
gardener_block.call
|
50
|
-
end
|
51
48
|
|
52
49
|
t2 = Thread.new do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
50
|
+
t1 = Thread.new do
|
51
|
+
gardener_block.call
|
52
|
+
end
|
53
|
+
|
54
|
+
until nil
|
55
|
+
if t1.stop?
|
56
|
+
if $seed.nil?
|
57
|
+
message_block = socket_duplex([:row,:row,@my_socket_path,@garden_path])
|
58
|
+
case message_block[1]
|
59
|
+
when :sprout
|
60
|
+
sprout(message_block)
|
61
|
+
when :all
|
62
|
+
all(message_block)
|
63
|
+
when :wait
|
64
|
+
message_block = socket_recv
|
65
|
+
case message_block[1]
|
66
|
+
when :sprout
|
67
|
+
sprout(message_block)
|
68
|
+
when :all
|
69
|
+
all(message_block)
|
70
|
+
when :init
|
71
|
+
init
|
72
|
+
when :quit
|
73
|
+
quit
|
74
|
+
end
|
75
|
+
when :init
|
76
|
+
init
|
77
|
+
when :quit
|
78
|
+
quit
|
79
|
+
end
|
80
|
+
elsif ! $seed[:success].nil?
|
81
|
+
crop
|
82
|
+
else
|
83
|
+
t1.run
|
84
|
+
end
|
85
|
+
end
|
83
86
|
end
|
84
87
|
end
|
85
88
|
t2.join
|
data/lib/rows_paths.rb
CHANGED
@@ -9,10 +9,12 @@ class Garden
|
|
9
9
|
module Paths
|
10
10
|
|
11
11
|
def all(message_block)
|
12
|
+
$log_abundance.debug("Rows::Paths") {"all"}
|
12
13
|
$seed = {:id => Process.pid, :seed => message_block[2], :all => true}
|
13
14
|
end
|
14
15
|
|
15
16
|
def crop
|
17
|
+
$log_abundance.debug("Rows::Paths") {"crop, seed: #{$seed.inspect}"}
|
16
18
|
if $seed[:all]
|
17
19
|
socket_send([:crop,:seed_all,$seed,@garden_path])
|
18
20
|
else
|
@@ -22,16 +24,19 @@ class Garden
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def init
|
27
|
+
$log_abundance.debug("Rows::Paths") {"init"}
|
25
28
|
$init = {:seed => 'init_status', :success => false, :message => 'No Init Message', :id => Process.pid} if $init.nil?
|
26
29
|
socket_send([:crop,:init,$init,@garden_path])
|
27
30
|
end
|
28
31
|
|
29
32
|
def quit
|
33
|
+
$log_abundance.debug("Rows::Paths") {"quit"}
|
30
34
|
socket_send([:close,:row,Process.pid,@garden_path])
|
31
|
-
|
35
|
+
Thread::exit
|
32
36
|
end
|
33
37
|
|
34
38
|
def sprout(message_block)
|
39
|
+
$log_abundance.debug("Rows::Paths") {"sprout"}
|
35
40
|
$seed = message_block[2]
|
36
41
|
end
|
37
42
|
|
data/lib/seed.rb
CHANGED
data/test/tc_burst.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'globalog'
|
2
3
|
require 'test/unit'
|
3
|
-
require 'abundance'
|
4
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), '..', 'lib', 'abundance')
|
4
5
|
|
5
6
|
class TestBurst < Test::Unit::TestCase
|
6
7
|
|
7
8
|
def test_burst1
|
9
|
+
@log_test.info("Test Burst") {"test burst1..."}
|
8
10
|
check_init
|
9
11
|
seed_1000x10
|
10
12
|
check_init
|
@@ -16,6 +18,7 @@ class TestBurst < Test::Unit::TestCase
|
|
16
18
|
|
17
19
|
|
18
20
|
def setup
|
21
|
+
@log_test = GlobaLog.logger(STDERR,:info)
|
19
22
|
@g = Abundance.gardener(:wheelbarrow => 124, :rows => 8, :init_timeout => 2) do
|
20
23
|
Abundance.init_status(true,Process.pid)
|
21
24
|
Abundance.grow do |seed|
|
@@ -33,6 +36,7 @@ class TestBurst < Test::Unit::TestCase
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def teardown
|
39
|
+
@log_test.info("test Burst") {"tearing down..."}
|
36
40
|
@g.close
|
37
41
|
end
|
38
42
|
|
data/test/tc_high_api.rb
CHANGED
@@ -1,28 +1,37 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'globalog'
|
2
3
|
require 'test/unit'
|
3
|
-
require 'abundance'
|
4
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), '..', 'lib', 'abundance')
|
4
5
|
|
5
6
|
class TestHighAPI < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@log_test = GlobaLog.logger(STDERR,:info)
|
10
|
+
end
|
6
11
|
|
7
|
-
def
|
12
|
+
def test_1_abundance_monothread
|
13
|
+
@log_test.info("Test High API") {"testing 1 thread..."}
|
8
14
|
@rows = 1
|
9
15
|
set_gardener
|
10
16
|
reality_check
|
11
17
|
end
|
12
18
|
|
13
|
-
def
|
19
|
+
def test_2_abundance_quadthread
|
20
|
+
@log_test.info("Test High API") {"testing 4 thread..."}
|
14
21
|
@rows = 4
|
15
22
|
set_gardener
|
16
23
|
reality_check
|
17
24
|
end
|
18
25
|
|
19
|
-
def
|
26
|
+
def test_3_abundance_hexthread
|
27
|
+
@log_test.info("Test High API") {"testing 16 thread..."}
|
20
28
|
@rows = 16
|
21
29
|
set_gardener
|
22
30
|
reality_check
|
23
31
|
end
|
24
32
|
|
25
33
|
def teardown
|
34
|
+
@log_test.info("Test High API") {"tearing down..."}
|
26
35
|
final = @g.close
|
27
36
|
assert_kind_of(Hash,final,"close method didn't return a Hash, it returned: #{final.inspect}")
|
28
37
|
assert_equal(3,final.size,"Hash returned on close has wrong size, here it is: #{final.inspect}")
|
data/test/tc_multi_gardener.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'globalog'
|
2
3
|
require 'test/unit'
|
3
|
-
require 'abundance'
|
4
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), '..', 'lib', 'abundance')
|
4
5
|
|
5
6
|
class TestMultiGardener < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@log_test = GlobaLog.logger(STDERR,:info)
|
10
|
+
end
|
6
11
|
|
7
12
|
def test_two_gardeners
|
13
|
+
@log_test.info("Test Multi Gardener") {"test two gardeners..."}
|
8
14
|
@rows = 2
|
9
15
|
set_gardener1
|
10
16
|
set_gardener2
|
data/test/tc_queue.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'globalog'
|
2
3
|
require 'test/unit'
|
3
|
-
require 'abundance'
|
4
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), '..', 'lib', 'abundance')
|
4
5
|
|
5
6
|
class TestQueue < Test::Unit::TestCase
|
6
7
|
|
7
8
|
def setup
|
9
|
+
@log_test = GlobaLog.logger(STDERR,:info)
|
8
10
|
@rows = 4
|
9
11
|
set_gardener
|
10
12
|
end
|
11
13
|
|
12
14
|
def test_queue
|
15
|
+
@log_test.info("Test Queue") {"test queue..."}
|
13
16
|
check_empty(true)
|
14
17
|
check_finished(true)
|
15
18
|
seed_lots
|
data/test/tc_robustness.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'globalog'
|
2
3
|
require 'test/unit'
|
3
|
-
require 'abundance'
|
4
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), '..', 'lib', 'abundance')
|
4
5
|
|
5
6
|
class TestRobustness < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@log_test = GlobaLog.logger(STDERR,:info)
|
10
|
+
end
|
6
11
|
|
7
12
|
def test_abundance_robust
|
13
|
+
@log_test.info("Test Robustness") {"test abundance robust..."}
|
8
14
|
@seed_size = 124
|
9
15
|
@rows = 8
|
10
16
|
@init_timeout = 3
|
data/test/ts_abundance.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
1
|
require 'test/unit'
|
3
|
-
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require 'test/tc_queue'
|
2
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'tc_high_api')
|
3
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'tc_robustness')
|
4
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'tc_multi_gardener')
|
5
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'tc_burst')
|
6
|
+
require File.join( File.dirname( File.expand_path(__FILE__)), 'tc_queue')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abundance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis-Philippe Perron
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-27 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: globalog
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.3
|
24
|
+
version:
|
16
25
|
description:
|
17
26
|
email: lp@spiralix.org
|
18
27
|
executables: []
|