celluloid-pool 0.10.0.pre4

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c55777df2d193b1653956397ba4526b28904008d
4
+ data.tar.gz: eae50db2ee716efc701bb49463579332487d13a0
5
+ SHA512:
6
+ metadata.gz: d1a4e00cfae73050b102f77ad35b29cc2b50ff5df6b124ad62cb34399ae155c9b2278c10baf2ce65c4e7266d0d84a463ce822956c6afd5abe14b26e2b5780e4a
7
+ data.tar.gz: 76ffaea263828668fc2fab44f5ec7244f91a39181d51425da935b92c6ef202c991e1da781abf55dca8ca3ccad54ba8f1ba2a5da04a4d6b7d989d7326b37c71de
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ log/*
2
+ coverage/*
3
+ Gemfile.lock
4
+ pkg/*
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "culture"]
2
+ path = culture
3
+ url = http://github.com/celluloid/culture.git
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format documentation
3
+ --order random
4
+ --warnings
5
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ inherit_from:
2
+ - culture/rubocop/rubocop.yml
3
+
data/.travis.yml ADDED
@@ -0,0 +1,32 @@
1
+ script: bundle exec rake
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.2.0
6
+ - jruby
7
+ - ruby-head
8
+ - jruby-head
9
+ - rbx-2
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: rbx-2
14
+ - rvm: ruby-head
15
+ - rvm: jruby-head
16
+ - env: CELLULOID_BACKPORTED=true
17
+
18
+ env:
19
+ matrix:
20
+ - CELLULOID_BACKPORTED=true
21
+ - CELLULOID_BACKPORTED=false
22
+ global:
23
+ - NUMBER_OF_PROCESSORS=2
24
+
25
+ notifications:
26
+ irc: "irc.freenode.org#celluloid"
27
+
28
+ before_install:
29
+ - if [ "$TRAVIS_RUBY_VERSION" == "rbx-2" ] ; then export BUNDLE_JOBS=1 ; else export BUNDLE_JOBS=4; fi
30
+
31
+ sudo: false
32
+ install: bundle install --without=development
data/CHANGES.md ADDED
@@ -0,0 +1,4 @@
1
+ 0.8.5 (2015.04.06)
2
+ -----
3
+ * Initial release of very old code *as gem* separate of Celluloid.
4
+ * Implemented `:injections` into `SupervisionGroup::Member` to resolve previous attachment requirements.
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ require File.expand_path("../culture/sync", __FILE__)
2
+ source "https://rubygems.org"
3
+
4
+ gemspec #de development_group: :gem_build_tools
5
+
6
+ group :development do
7
+ gem "pry"
8
+ # de gem 'guard'
9
+ # de gem 'guard-rspec'
10
+ # de gem 'rb-fsevent', '~> 0.9.1' if RUBY_PLATFORM =~ /darwin/
11
+ end
12
+
13
+ group :test do
14
+ gem "dotenv", "~> 2.0"
15
+ gem "nenv"
16
+ gem "benchmark_suite"
17
+ gem "rspec", "~> 3.2"
18
+ end
19
+
20
+ group :gem_build_tools do
21
+ gem "rake"
22
+ end
23
+
24
+ Celluloid::Sync.gems(self)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chris Heald
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ ## Actor pools for Celluloid.
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/celluloid-pool.svg)](http://badge.fury.io/rb/celluloid-pool)
4
+
5
+ Documentation coming.
6
+
7
+ > This gem is in prerelease.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir["tasks/**/*.rake"].each { |task| load task }
4
+
5
+ default_tasks = ["spec"]
6
+ default_tasks << "rubocop" unless ENV["CI"]
7
+ task default: default_tasks
8
+
9
+ task ci: %w(spec benchmark)
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ require File.expand_path("../culture/sync", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "celluloid-pool"
6
+ gem.version = "0.10.0.pre4"
7
+ gem.authors = ["Tony Arcieri", "Tim Carey-Smith", "digitalextremist //"]
8
+ gem.email = ["tony.arcieri@gmail.com", "code@extremist.digital"]
9
+
10
+ gem.summary = "An implementation of an actor pool, based on the Celluloid concurrent object framework."
11
+ gem.description = "An implementation of an actor pool, based on the Celluloid concurrent object framework."
12
+ gem.homepage = "http://github.com/celluloid/celluloid-pool"
13
+ gem.license = "MIT"
14
+
15
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|examples|spec|features)/}) }
16
+ gem.require_paths = ["lib"]
17
+
18
+ Celluloid::Sync.gems(gem)
19
+ end
@@ -0,0 +1,6 @@
1
+ require "celluloid" unless defined? Celluloid
2
+
3
+ require "celluloid/supervision"
4
+
5
+ require "celluloid/supervision/container/pool"
6
+ require "celluloid/supervision/container/behavior/pool"
@@ -0,0 +1,61 @@
1
+ require "set"
2
+
3
+ module Celluloid
4
+ module ClassMethods
5
+ # Create a new pool of workers. Accepts the following options:
6
+ #
7
+ # * size: how many workers to create. Default is worker per CPU core
8
+ # * args: array of arguments to pass when creating a worker
9
+ #
10
+ def pool(config={})
11
+ Celluloid.services.supervise(config.merge(type: Supervision::Container::Pool, args: [{workers: self}]))
12
+ Celluloid.services.actors.last
13
+ end
14
+
15
+ # Same as pool, but links to the pool manager
16
+ def pool_link(klass, config={})
17
+ Supervision::Container::Pool.new_link(
18
+ config.merge(args: [{workers: klass}]),
19
+ )
20
+ end
21
+ end
22
+
23
+ module Supervision
24
+ class Container
25
+ def pool(klass, config={})
26
+ Celluloid.services.supervise(config.merge(type: Container::Pool, args: [{workers: klass}]))
27
+ Celluloid.services.actors.last
28
+ end
29
+
30
+ class Instance
31
+ attr_accessor :pool, :pool_size
32
+ end
33
+
34
+ class << self
35
+ # Register a pool of actors to be launched on group startup
36
+ def pool(klass, *args, &_block)
37
+ blocks << lambda do |container|
38
+ container.pool(klass, Configuration.options(args))
39
+ end
40
+ end
41
+ end
42
+
43
+ class Pool
44
+ include Behavior
45
+
46
+ identifier! :size, :pool
47
+
48
+ configuration do
49
+ puts "configuring pool"
50
+ @supervisor = Container::Pool
51
+ @method = "pool_link"
52
+ @pool = true
53
+ @pool_size = @cofiguration[:size]
54
+ @configuration
55
+ end
56
+ end
57
+
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,183 @@
1
+ module Celluloid
2
+ module Supervision
3
+ class Container
4
+ # Manages a fixed-size pool of workers
5
+ # Delegates work (i.e. methods) and supervises workers
6
+ # Don't use this class directly. Instead use MyKlass.pool
7
+ class Pool
8
+
9
+ include Celluloid
10
+
11
+ trap_exit :__crash_handler__
12
+ finalizer :__shutdown__
13
+
14
+ def initialize(options={})
15
+ @idle = []
16
+ @busy = []
17
+ @workers = options[:workers]
18
+ @args = {}
19
+ @size = 0
20
+
21
+ #de options = Supervision::Configuration.options(options)
22
+ @size = options[:size] || [Celluloid.cores || 2, 2].max
23
+ @args = options[:args] ? Array(options[:args]) : []
24
+
25
+ fail ArgumentError, "minimum pool size is 2" if @size < 2
26
+
27
+ # Do this last since it can suspend and/or crash
28
+ @idle = @size.times.map { @workers.new_link(*@args) }
29
+ end
30
+
31
+ def __shutdown__
32
+ # TODO: these can be nil if initializer crashes
33
+ terminators = (@idle + @busy).map do |actor|
34
+ begin
35
+ actor.future(:terminate)
36
+ rescue DeadActorError
37
+ end
38
+ end
39
+
40
+ terminators.compact.each { |terminator| terminator.value rescue nil }
41
+ end
42
+
43
+ def _send_(method, *args, &block)
44
+ worker = __provision_worker__
45
+
46
+ begin
47
+ worker._send_ method, *args, &block
48
+ rescue DeadActorError # if we get a dead actor out of the pool
49
+ wait :respawn_complete
50
+ worker = __provision_worker__
51
+ retry
52
+ rescue Exception => ex
53
+ abort ex
54
+ ensure
55
+ if worker.alive?
56
+ @idle << worker
57
+ @busy.delete worker
58
+
59
+ # Broadcast that worker is done processing and
60
+ # waiting idle
61
+ signal :worker_idle
62
+ end
63
+ end
64
+ end
65
+
66
+ def name
67
+ _send_ @mailbox, :name
68
+ end
69
+
70
+ def is_a?(klass)
71
+ _send_ :is_a?, klass
72
+ end
73
+
74
+ def kind_of?(klass)
75
+ _send_ :kind_of?, klass
76
+ end
77
+
78
+ def methods(include_ancestors = true)
79
+ _send_ :methods, include_ancestors
80
+ end
81
+
82
+ def to_s
83
+ _send_ :to_s
84
+ end
85
+
86
+ def inspect
87
+ _send_ :inspect
88
+ end
89
+
90
+ attr_reader :size
91
+
92
+ def size=(new_size)
93
+ new_size = [0, new_size].max
94
+
95
+ if new_size > size
96
+ delta = new_size - size
97
+ delta.times { @idle << @workers.new_link(*@args) }
98
+ else
99
+ (size - new_size).times do
100
+ worker = __provision_worker__
101
+ unlink worker
102
+ @busy.delete worker
103
+ worker.terminate
104
+ end
105
+ end
106
+ @size = new_size
107
+ end
108
+
109
+ def busy_size
110
+ @busy.length
111
+ end
112
+
113
+ def idle_size
114
+ @idle.length
115
+ end
116
+
117
+ # Provision a new worker
118
+ def __provision_worker__
119
+ Task.current.guard_warnings = true
120
+ while @idle.empty?
121
+ # Wait for responses from one of the busy workers
122
+ response = exclusive { receive { |msg| msg.is_a?(Internals::Response) } }
123
+ Thread.current[:celluloid_actor].handle_message(response)
124
+ end
125
+
126
+ worker = @idle.shift
127
+ @busy << worker
128
+
129
+ worker
130
+ end
131
+
132
+ # Spawn a new worker for every crashed one
133
+ def __crash_handler__(actor, reason)
134
+ @busy.delete actor
135
+ @idle.delete actor
136
+ return unless reason
137
+
138
+ @idle << @workers.new_link(*@args)
139
+ signal :respawn_complete
140
+ end
141
+
142
+ def respond_to?(meth, include_private = false)
143
+ # NOTE: use method() here since this class
144
+ # shouldn't be used directly, and method() is less
145
+ # likely to be "reimplemented" inconsistently
146
+ # with other Object.*method* methods.
147
+
148
+ found = method(meth)
149
+ if include_private
150
+ found ? true : false
151
+ else
152
+ if found.is_a?(UnboundMethod)
153
+ found.owner.public_instance_methods.include?(meth) ||
154
+ found.owner.protected_instance_methods.include?(meth)
155
+ else
156
+ found.receiver.public_methods.include?(meth) ||
157
+ found.receiver.protected_methods.include?(meth)
158
+ end
159
+ end
160
+ rescue NameError
161
+ false
162
+ end
163
+
164
+ def method_missing(method, *args, &block)
165
+ if respond_to?(method)
166
+ _send_ method, *args, &block
167
+ else
168
+ super
169
+ end
170
+ end
171
+
172
+ # Since Pool allocates worker objects only just before calling them,
173
+ # we can still help Celluloid::Call detect passing invalid parameters to
174
+ # async methods by checking for those methods on the worker class
175
+ def method(meth)
176
+ super
177
+ rescue NameError
178
+ @workers.instance_method(meth.to_sym)
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,16 @@
1
+ require "timeout"
2
+
3
+ desc "Run Celluloid benchmarks"
4
+ task :benchmark do
5
+ begin
6
+ Timeout.timeout(120) do
7
+ glob = File.expand_path("../../benchmarks/*.rb", __FILE__)
8
+ Dir[glob].each { |benchmark| load benchmark }
9
+ end
10
+ rescue Exception, Timeout::Error => ex
11
+ puts "ERROR: Couldn't complete benchmark: #{ex.class}: #{ex}"
12
+ puts " #{ex.backtrace.join("\n ")}"
13
+
14
+ exit 1 unless ENV["CI"] # Hax for running benchmarks on Travis
15
+ end
16
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,7 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
@@ -0,0 +1,4 @@
1
+ unless ENV["CI"]
2
+ require "rubocop/rake_task"
3
+ RuboCop::RakeTask.new
4
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: celluloid-pool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0.pre4
5
+ platform: ruby
6
+ authors:
7
+ - Tony Arcieri
8
+ - Tim Carey-Smith
9
+ - digitalextremist //
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-05-04 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ name: bundler
22
+ prerelease: false
23
+ type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ name: rubocop
36
+ prerelease: false
37
+ type: :runtime
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ name: coveralls
50
+ prerelease: false
51
+ type: :runtime
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ name: celluloid
64
+ prerelease: false
65
+ type: :development
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ name: celluloid-essentials
78
+ prerelease: false
79
+ type: :development
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ name: celluloid-supervision
92
+ prerelease: false
93
+ type: :development
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ name: celluloid-fsm
106
+ prerelease: false
107
+ type: :development
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ name: celluloid-extras
120
+ prerelease: false
121
+ type: :development
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ name: timers
134
+ prerelease: false
135
+ type: :runtime
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ name: rspec-logsplit
148
+ prerelease: false
149
+ type: :runtime
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ description: An implementation of an actor pool, based on the Celluloid concurrent object framework.
156
+ email:
157
+ - tony.arcieri@gmail.com
158
+ - code@extremist.digital
159
+ executables: []
160
+ extensions: []
161
+ extra_rdoc_files: []
162
+ files:
163
+ - .gitignore
164
+ - .gitmodules
165
+ - .rspec
166
+ - .rubocop.yml
167
+ - .travis.yml
168
+ - CHANGES.md
169
+ - Gemfile
170
+ - LICENSE.txt
171
+ - README.md
172
+ - Rakefile
173
+ - celluloid-pool.gemspec
174
+ - lib/celluloid/pool.rb
175
+ - lib/celluloid/supervision/container/behavior/pool.rb
176
+ - lib/celluloid/supervision/container/pool.rb
177
+ - tasks/benchmarks.rake
178
+ - tasks/rspec.rake
179
+ - tasks/rubocop.rake
180
+ homepage: http://github.com/celluloid/celluloid-pool
181
+ licenses:
182
+ - MIT
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - '>'
196
+ - !ruby/object:Gem::Version
197
+ version: 1.3.1
198
+ requirements: []
199
+ rubyforge_project:
200
+ rubygems_version: 2.4.6
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: An implementation of an actor pool, based on the Celluloid concurrent object framework.
204
+ test_files: []