team_effort 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/LICENSE +20 -0
- data/README.md +63 -0
- data/Rakefile +9 -0
- data/lib/team_effort.rb +23 -0
- data/lib/team_effort/version.rb +3 -0
- data/team_effort.gemspec +26 -0
- data/test/test_team_effort.rb +33 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: caad20978d09546b723794fedd95ca0d341c1044
|
4
|
+
data.tar.gz: b1fee646c8cae6b0cdf5b10c1441f0df6e454e56
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebcae5593ecede37d63f3e6711ba2f8b08a28795d9e85c179107e80993396c236b748a69f9930f2fbe6734c0341149ff13b9154272fe7b799eb946ca7144cde3
|
7
|
+
data.tar.gz: 63f51a5f48c662fceecb4823a6d46f45cea15428b21db0ef2b84d6728a52524e65ea84515a7ef0a36ef8da198b0c676c51442a7c4cdcdb5519adcbfab99505be
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
team_effort
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Kelly Felkins
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# TeamEffort
|
2
|
+
|
3
|
+
Team Effort is a module that makes it easy to dispatch work to child
|
4
|
+
processes allowing you to speed processing by taking advantage of
|
5
|
+
multiple cores.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'team_effort'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install team_effort
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To do work in child processes just call `TeamEffort.work` with a collection
|
24
|
+
of items to process and a block:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
class ProcessALotOfStuff
|
28
|
+
|
29
|
+
def some_method
|
30
|
+
# collection = a lot of stuff from somewhere
|
31
|
+
TeamEffort.work(collection) do |item|
|
32
|
+
# do some work on item
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
You may specify the number of child processes with the work method:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
def some_method
|
43
|
+
# collection = a lot of stuff from somewhere
|
44
|
+
TeamEffort.work(collection, 3) do |item| # do the work using 3 child processes
|
45
|
+
# do some work on item
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
The number of child processes defaults to 4.
|
51
|
+
|
52
|
+
The work method will create a new child process for each item in the
|
53
|
+
enumeration using ruby's Process.fork so there is overhead on each
|
54
|
+
item processed. Team Effort works best when there is substantial work
|
55
|
+
to be performed on each item to minimize overhead.
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/team_effort.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "team_effort/version"
|
2
|
+
|
3
|
+
module TeamEffort
|
4
|
+
def self.work(enumerable, max_process_count = 4)
|
5
|
+
pids = []
|
6
|
+
|
7
|
+
enumerable.each do |args|
|
8
|
+
if pids.size == max_process_count
|
9
|
+
finished_pid = Process.wait
|
10
|
+
pids.delete finished_pid
|
11
|
+
end
|
12
|
+
|
13
|
+
pids << fork do
|
14
|
+
yield args
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
while !pids.empty?
|
19
|
+
finished_pid = Process.wait
|
20
|
+
pids.delete finished_pid
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/team_effort.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'team_effort/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "team_effort"
|
8
|
+
spec.version = TeamEffort::VERSION
|
9
|
+
spec.authors = ["Kelly Felkins"]
|
10
|
+
spec.email = ["kelly@restlater.com"]
|
11
|
+
spec.description = <<-EOT
|
12
|
+
Team Effort provides a simple wrapper to ruby's process management for
|
13
|
+
processing a collection of items in parallel with child processes.
|
14
|
+
EOT
|
15
|
+
spec.summary = %q{Use child processes to process a collection in parallel}
|
16
|
+
spec.homepage = "https://github.com/kellyfelkins/team_effort"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../lib/team_effort'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
describe TeamEffort do
|
6
|
+
describe '#work' do
|
7
|
+
it 'performs work in child processes' do
|
8
|
+
mutex = Mutex.new
|
9
|
+
output_io = Tempfile.new('mumble')
|
10
|
+
output = nil
|
11
|
+
begin
|
12
|
+
data = %w|one two three|
|
13
|
+
TeamEffort.work(data) do |item|
|
14
|
+
mutex.synchronize do
|
15
|
+
output_io.puts Process.pid
|
16
|
+
output_io.flush
|
17
|
+
end
|
18
|
+
end
|
19
|
+
output_io.rewind
|
20
|
+
output = output_io.read
|
21
|
+
ensure
|
22
|
+
output_io.close
|
23
|
+
output_io.unlink
|
24
|
+
end
|
25
|
+
|
26
|
+
lines = output.split(/\n/)
|
27
|
+
lines.size.must_equal 3
|
28
|
+
lines.each do |line|
|
29
|
+
line.must_match /^\d+$/
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: team_effort
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kelly Felkins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: " Team Effort provides a simple wrapper to ruby's process management
|
42
|
+
for \n processing a collection of items in parallel with child processes.\n"
|
43
|
+
email:
|
44
|
+
- kelly@restlater.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- .ruby-gemset
|
51
|
+
- .ruby-version
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/team_effort.rb
|
56
|
+
- lib/team_effort/version.rb
|
57
|
+
- team_effort.gemspec
|
58
|
+
- test/test_team_effort.rb
|
59
|
+
homepage: https://github.com/kellyfelkins/team_effort
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.0.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Use child processes to process a collection in parallel
|
83
|
+
test_files:
|
84
|
+
- test/test_team_effort.rb
|