celluloid-pmap 0.2.2 → 1.0.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.
- checksums.yaml +5 -5
- data/.travis.yml +63 -6
- data/Appraisals +17 -0
- data/README.md +31 -16
- data/Rakefile +32 -4
- data/celluloid-pmap.gemspec +4 -3
- data/gemfiles/celluloid_0.16.0.gemfile +7 -0
- data/gemfiles/celluloid_0.17.3.gemfile +7 -0
- data/gemfiles/celluloid_0.17.4.gemfile +7 -0
- data/gemfiles/celluloid_0.18.0.gemfile +7 -0
- data/lib/celluloid/pmap.rb +14 -1
- data/lib/celluloid/pmap/version.rb +1 -1
- data/spec/celluloid/pmap/parallel_map_worker_spec.rb +1 -1
- data/spec/celluloid/pmap_spec.rb +2 -2
- data/spec/spec_helper.rb +20 -1
- metadata +28 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0314d3de53bd90a5fc404c270eaae816085b4d4e064d130acb54ee7232aed0ea
|
4
|
+
data.tar.gz: dd4998ad61f59a449abcec2b11266d7679aab0411c575fea539b93b4ffd9e5a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 521bfb16017e3daa6304565129e8ba512d05ebafd642ab3a47869d987204d1bf789508a4761d6d6408274b3d1ef80178bff69814ce554eca29dc2242b081608d
|
7
|
+
data.tar.gz: bdced35769e0299dc4d9666b2b06b48ee8afed4f6cab2f64a273341fbc6217cefcf929a70e9b9e2b6a2ff2d5d42c1b1dc9d4de3baa432e5196af374fee7fb4e9
|
data/.travis.yml
CHANGED
@@ -1,7 +1,64 @@
|
|
1
|
-
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
cache: bundler
|
4
|
+
|
5
|
+
bundler_args: --no-deployment --binstubs=./bin
|
6
|
+
|
7
|
+
before_install:
|
8
|
+
- "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
|
9
|
+
- if [[ ! "${RUBY_VERSION}" =~ "jruby" ]]; then travis_wait 30 rvm rubygems current; fi
|
10
|
+
- if [[ ! "${RUBY_VERSION}" =~ "jruby" ]]; then yes | gem update --system --force || true; fi
|
11
|
+
- gem --version
|
12
|
+
- gem install bundler -v 1.17.3
|
13
|
+
- export MY_BUNDLER_VERSION='_1.17.3_'
|
14
|
+
- bundle ${MY_BUNDLER_VERSION} --version
|
15
|
+
|
16
|
+
install:
|
17
|
+
- bundle ${MY_BUNDLER_VERSION} config --local path vendor/bundle
|
18
|
+
- bundle ${MY_BUNDLER_VERSION} config --local jobs 3
|
19
|
+
- bundle ${MY_BUNDLER_VERSION} config --local retry 3
|
20
|
+
- bundle ${MY_BUNDLER_VERSION} config --local binstubs ./bin
|
21
|
+
- bundle ${MY_BUNDLER_VERSION} config --local bin ./bin
|
22
|
+
- bundle ${MY_BUNDLER_VERSION} install
|
23
|
+
|
24
|
+
script:
|
25
|
+
- echo $BUNDLE_GEMFILE
|
26
|
+
- bundle ${MY_BUNDLER_VERSION} exec rake
|
27
|
+
|
28
|
+
gemfile:
|
29
|
+
- gemfiles/celluloid_0.16.0.gemfile
|
30
|
+
- gemfiles/celluloid_0.17.3.gemfile
|
31
|
+
- gemfiles/celluloid_0.17.4.gemfile
|
32
|
+
- gemfiles/celluloid_0.18.0.gemfile
|
33
|
+
matrix:
|
34
|
+
fast_finish: true
|
35
|
+
allow_failures:
|
36
|
+
- rvm: jruby-19mode
|
37
|
+
- rvm: jruby-head
|
38
|
+
exclude:
|
39
|
+
- rvm: 2.0.0
|
40
|
+
gemfile: gemfiles/celluloid_0.18.0.gemfile
|
41
|
+
- rvm: 2.1.3
|
42
|
+
gemfile: gemfiles/celluloid_0.18.0.gemfile
|
43
|
+
- rvm: 2.2.0
|
44
|
+
gemfile: gemfiles/celluloid_0.18.0.gemfile
|
45
|
+
- rvm: 2.2.2
|
46
|
+
gemfile: gemfiles/celluloid_0.18.0.gemfile
|
47
|
+
- rvm: 2.2.5
|
48
|
+
gemfile: gemfiles/celluloid_0.18.0.gemfile
|
2
49
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
-
|
7
|
-
-
|
50
|
+
- 2.1.3
|
51
|
+
- 2.2.2
|
52
|
+
- 2.3.1
|
53
|
+
- 2.3.2
|
54
|
+
- 2.3.3
|
55
|
+
- 2.4.0
|
56
|
+
- 2.5.3
|
57
|
+
- 2.6.5
|
58
|
+
- 2.7.1
|
59
|
+
- 3.0.0
|
60
|
+
- jruby-19mode
|
61
|
+
- jruby-head
|
62
|
+
|
63
|
+
env:
|
64
|
+
- RACK_ENV=test
|
data/Appraisals
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
appraise "celluloid-0.16.0" do
|
2
|
+
gem "celluloid", "0.16.0"
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "celluloid-0.17.3" do
|
6
|
+
gem "celluloid", "0.17.3"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "celluloid-0.17.4" do
|
10
|
+
gem "celluloid", "0.17.4"
|
11
|
+
end
|
12
|
+
|
13
|
+
if RUBY_VERSION >= '2.2.6'
|
14
|
+
appraise "celluloid-0.18.0" do
|
15
|
+
gem "celluloid", "0.18.0"
|
16
|
+
end
|
17
|
+
end
|
data/README.md
CHANGED
@@ -10,9 +10,10 @@ implementation AND a supervisor to keep the max threads down, you can be wicked
|
|
10
10
|
sweet too!
|
11
11
|
|
12
12
|
### How does this happen?
|
13
|
+
|
13
14
|

|
14
15
|
|
15
|
-
We use Celluloid Futures and Celluloid pool to execute blocks in parallel.
|
16
|
+
We use Celluloid Futures and Celluloid pool to execute blocks in parallel.
|
16
17
|
|
17
18
|
The pmap will return an array of values when all of the Futures have completed and return values (or return nil).
|
18
19
|
|
@@ -30,7 +31,6 @@ users.pmap(4) do |user|
|
|
30
31
|
end
|
31
32
|
```
|
32
33
|
|
33
|
-
|
34
34
|
### Inspiration for this code
|
35
35
|
|
36
36
|
Tony Arcieri created [celluloid](http://celluloid.io/), and the [simple_pmap example](https://github.com/celluloid/celluloid/blob/master/examples/simple_pmap.rb) from which this codebase started
|
@@ -43,20 +43,35 @@ I've used this implementation in several production systems over the last year.
|
|
43
43
|
|
44
44
|
Because I've been implementing the same initializer code in every project I've worked on for the last 6 months. It was time to take a stand, man.
|
45
45
|
|
46
|
-
### What
|
46
|
+
### What versions of Celluloid?
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
* jruby-head
|
48
|
+
- 0.16.0
|
49
|
+
- 0.17.3
|
50
|
+
- 0.17.4
|
51
|
+
- 0.18.0
|
53
52
|
|
53
|
+
### What rubies will this run on?
|
54
|
+
|
55
|
+
- 2.1.3
|
56
|
+
- 2.2.2
|
57
|
+
- 2.3.1
|
58
|
+
- 2.3.2
|
59
|
+
- 2.3.3
|
60
|
+
- 2.4.0
|
61
|
+
- 2.5.3
|
62
|
+
- 2.6.5
|
63
|
+
- 2.7.1
|
64
|
+
- 3.0.0
|
65
|
+
- jruby-19mode
|
66
|
+
- jruby-head
|
54
67
|
|
55
68
|
## Installation
|
56
69
|
|
57
70
|
Add this line to your application's Gemfile:
|
58
71
|
|
59
|
-
|
72
|
+
```ruby
|
73
|
+
gem 'celluloid-pmap', '1.0'
|
74
|
+
```
|
60
75
|
|
61
76
|
## Usage
|
62
77
|
|
@@ -72,7 +87,7 @@ puts "You'll see the puts happen instantly, and the sleep in parallel"
|
|
72
87
|
Or something more real-world?
|
73
88
|
|
74
89
|
```
|
75
|
-
User.active.all.pmap do |user|
|
90
|
+
User.active.all.pmap do |user|
|
76
91
|
stripe_user = Stripe::Customer.retrieve user.stripe_customer_token
|
77
92
|
user.invoices = BuildsInvoicesFromStripeUser.build(stripe_user)
|
78
93
|
user.save
|
@@ -100,13 +115,13 @@ When you need the response right away. (well, right away in the workflow sense).
|
|
100
115
|
|
101
116
|
### When will this help performance?
|
102
117
|
|
103
|
-
|
104
|
-
|
105
|
-
|
118
|
+
- When the blocks are IO bound (like database or web queries)
|
119
|
+
- When you're running JRuby or Rubinius
|
120
|
+
- When you're running C Extensions
|
106
121
|
|
107
122
|
### So what will this not speed things up?
|
108
123
|
|
109
|
-
|
124
|
+
- Pure math or ruby computations\*
|
110
125
|
|
111
126
|
\*except if you're on JRuby or Rubinius, where this will still speed those along quite nicely.
|
112
127
|
|
@@ -120,8 +135,8 @@ More information on He-Man can be found at the unspeakably wow site: http://cast
|
|
120
135
|
|
121
136
|
## Contributors
|
122
137
|
|
123
|
-
|
124
|
-
|
138
|
+
- [Jason Voegele](https://github.com/jvoegele)
|
139
|
+
- [rada bogdan raul](https://github.com/bogdanRada)
|
125
140
|
|
126
141
|
## Contributing
|
127
142
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,34 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'appraisal'
|
3
4
|
require 'rspec/core/rake_task'
|
4
|
-
RSpec::Core::RakeTask.new('spec')
|
5
5
|
|
6
|
-
|
6
|
+
# a little hack for RSpec::Core::RakeTask
|
7
|
+
::Rake.application.class.class_eval do
|
8
|
+
alias_method :last_comment, :last_description
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
12
|
+
spec.rspec_opts = ['--backtrace '] if ENV['DEBUG']
|
13
|
+
spec.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Default: run the unit tests.'
|
17
|
+
task default: [:all]
|
18
|
+
|
19
|
+
desc 'Test the plugin under all supported Celluloid versions.'
|
20
|
+
task :all do |_t|
|
21
|
+
if ENV['TRAVIS']
|
22
|
+
# require 'json'
|
23
|
+
# puts JSON.pretty_generate(ENV.to_hash)
|
24
|
+
if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
|
25
|
+
appraisal_name = ENV['BUNDLE_GEMFILE'].scan(/celluloid\_(.*)\.gemfile/).flatten.first
|
26
|
+
command_prefix = "appraisal celluloid-#{appraisal_name}"
|
27
|
+
exec ("#{command_prefix} bundle install && #{command_prefix} bundle exec rspec")
|
28
|
+
else
|
29
|
+
exec(' bundle exec appraisal install && bundle exec rake appraisal spec')
|
30
|
+
end
|
31
|
+
else
|
32
|
+
exec('bundle exec appraisal install && bundle exec rake appraisal spec')
|
33
|
+
end
|
34
|
+
end
|
data/celluloid-pmap.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
|
4
|
-
require 'celluloid/pmap/version'
|
2
|
+
require 'date'
|
3
|
+
require File.expand_path('../lib/celluloid/pmap/version', __FILE__)
|
5
4
|
|
6
5
|
Gem::Specification.new do |gem|
|
7
6
|
gem.name = "celluloid-pmap"
|
@@ -12,6 +11,7 @@ Gem::Specification.new do |gem|
|
|
12
11
|
gem.summary = %q{ Celluloid Futures are wicked sweet, and when combined with a #pmap implementation AND a supervisor to keep the max threads down, you can be wicked sweet too!}
|
13
12
|
gem.homepage = "https://github.com/jwo/celluloid-pmap"
|
14
13
|
gem.license = "MIT"
|
14
|
+
gem.date = Date.today
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.add_development_dependency "rake"
|
24
24
|
gem.add_development_dependency "rspec", "2.99"
|
25
25
|
gem.add_development_dependency "pry"
|
26
|
+
gem.add_development_dependency 'appraisal', '~> 2.1', '>= 2.1'
|
26
27
|
end
|
data/lib/celluloid/pmap.rb
CHANGED
@@ -8,13 +8,26 @@ module Celluloid
|
|
8
8
|
Gem.loaded_specs.values.detect{|repo| repo.name == name }
|
9
9
|
end
|
10
10
|
|
11
|
+
def self.ensure_celluloid_running
|
12
|
+
celluloid_running = Celluloid.running? rescue false
|
13
|
+
Celluloid.boot unless celluloid_running
|
14
|
+
end
|
15
|
+
|
11
16
|
def self.pool_class
|
12
17
|
celluloid_version = find_loaded_gem("celluloid").version.to_s.split('.')
|
13
18
|
if celluloid_version[0].to_i == 0 && celluloid_version[1].to_i <= 16
|
14
19
|
require 'celluloid'
|
20
|
+
require 'celluloid/autostart'
|
21
|
+
ensure_celluloid_running
|
15
22
|
Celluloid::PoolManager
|
16
|
-
|
23
|
+
elsif celluloid_version[0].to_i == 0 && celluloid_version[1].to_i < 18
|
17
24
|
require 'celluloid/current'
|
25
|
+
ensure_celluloid_running
|
26
|
+
Celluloid::Supervision::Container::Pool
|
27
|
+
else
|
28
|
+
require 'celluloid'
|
29
|
+
require 'celluloid/pool'
|
30
|
+
ensure_celluloid_running
|
18
31
|
Celluloid::Supervision::Container::Pool
|
19
32
|
end
|
20
33
|
end
|
data/spec/celluloid/pmap_spec.rb
CHANGED
@@ -21,14 +21,14 @@ describe Celluloid::Pmap do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should sleep in parallel for pmap' do
|
24
|
-
Celluloid.
|
24
|
+
allow(Celluloid).to receive(:cores).and_return(4)
|
25
25
|
expect {
|
26
26
|
[1,2,3].pmap{|x| x; sleep(1) }
|
27
27
|
}.to take_approximately(1).seconds
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should default to the number of cores on the machine' do
|
31
|
-
Celluloid.
|
31
|
+
allow(Celluloid).to receive(:cores).and_return(4)
|
32
32
|
expect {
|
33
33
|
[1,2,3,4,5,6].pmap{|x| x; sleep(1) }
|
34
34
|
}.to take_approximately(2).seconds
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
-
|
1
|
+
require 'bundler/setup'
|
2
2
|
require 'celluloid/pmap'
|
3
3
|
require 'support/benchmark_spec'
|
4
|
+
require 'logger'
|
5
|
+
Celluloid::Pmap.pool_class
|
6
|
+
|
7
|
+
Celluloid.task_class = if defined?(Celluloid::TaskThread)
|
8
|
+
Celluloid::TaskThread
|
9
|
+
else
|
10
|
+
Celluloid::Task::Threaded
|
11
|
+
end
|
12
|
+
Celluloid.logger = ::Logger.new(STDOUT)
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.around(:each) do |example|
|
16
|
+
celluloid_running = Celluloid.running? rescue false
|
17
|
+
Celluloid.shutdown if celluloid_running
|
18
|
+
Celluloid.boot
|
19
|
+
example.run
|
20
|
+
Celluloid.shutdown
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid-pmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Wolgamott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -66,6 +66,26 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: appraisal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.1'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.1'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.1'
|
69
89
|
description: Easy Parallel Executing using Celluloid
|
70
90
|
email:
|
71
91
|
- jesse@comalproductions.com
|
@@ -76,11 +96,16 @@ files:
|
|
76
96
|
- ".gitignore"
|
77
97
|
- ".rspec"
|
78
98
|
- ".travis.yml"
|
99
|
+
- Appraisals
|
79
100
|
- Gemfile
|
80
101
|
- LICENSE.txt
|
81
102
|
- README.md
|
82
103
|
- Rakefile
|
83
104
|
- celluloid-pmap.gemspec
|
105
|
+
- gemfiles/celluloid_0.16.0.gemfile
|
106
|
+
- gemfiles/celluloid_0.17.3.gemfile
|
107
|
+
- gemfiles/celluloid_0.17.4.gemfile
|
108
|
+
- gemfiles/celluloid_0.18.0.gemfile
|
84
109
|
- lib/celluloid/pmap.rb
|
85
110
|
- lib/celluloid/pmap/parallel_map_worker.rb
|
86
111
|
- lib/celluloid/pmap/version.rb
|
@@ -107,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
132
|
- !ruby/object:Gem::Version
|
108
133
|
version: '0'
|
109
134
|
requirements: []
|
110
|
-
|
111
|
-
rubygems_version: 2.4.5.1
|
135
|
+
rubygems_version: 3.1.2
|
112
136
|
signing_key:
|
113
137
|
specification_version: 4
|
114
138
|
summary: 'Celluloid Futures are wicked sweet, and when combined with a #pmap implementation
|