chantier 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02886ce2234ab79bd1088a0ef7964d3a52046a94
4
- data.tar.gz: e9facf80639b5f4cee600a21356a51f85181c699
3
+ metadata.gz: 733102f569568fbb2f2953e74298840e6cddd625
4
+ data.tar.gz: 0753643bc032abc303a72f212dab29f7691338ec
5
5
  SHA512:
6
- metadata.gz: ee8e5e32959c699e69bb4d33a5d5101843a24427ed0d61db8d73fe4ce34bf769949d0554e61457faa3597aef4408dbccca8ed92c71d2ffaa83bdf5da175eb378
7
- data.tar.gz: efe1866c848fa2ebc49a8324b10741725eaea701ad4cdd69aed35bf41852f530473c6e29ce29320466e67cec888e973e698649be983e3bb6bd58b362abb5f5fa
6
+ metadata.gz: 8b34b053dba7b457a0d4561c5fff71f14a8fa7e96314c0c9d209c539f874255da769ecd89b1fd96e4e8d1011c4dce4c4ef9b30ddbdd67f9ce8147e3396b93193
7
+ data.tar.gz: dd1101a603f7f83a28af4ebfd74734daadeecadeeef069987ced8947d5a73b5b527fda0a8f5040bd47409ecd39972b5a8d2e6b502f8f8813f942887fb160dff3
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = chantier
2
2
 
3
- Dead-simple task manager for "fire and forget" jobs. Has two interchangeable pools - processes and threads, which
4
- are interchangeable.
3
+ Dead-simple task manager for "fire and forget" jobs. Has two interchangeable pools - processes and threads. The API
4
+ of those two is the same, so you can play at will and figure out which one works better.
5
5
 
6
6
  The only thing Chantier checks for is that the spun off tasks have completed. It also limits the number of tasks
7
7
  active at the same time. Your code will block until a slot becomes available for a task.
@@ -15,17 +15,21 @@ active at the same time. Your code will block until a slot becomes available for
15
15
  end
16
16
 
17
17
  manager.block_until_complete! #=> Will block until all the subprocesses have terminated
18
-
19
- If you have a finite Enumerable at hand you can also launch it into the ProcessPool, like so:
18
+
19
+ If you have a finite Enumerable at hand you can also launch it into the ProcessPool/ThreadPool, like so:
20
20
 
21
21
  manager = Chantier::ThreadPool.new(slots = 4)
22
22
 
23
- manager.map_fork(job_tickets) do | job_ticket |
24
- # this block will run in a forked subprocess
25
- Churner.new(job).churn
23
+ manager.map_fork(job_tickets) do | job_ticket | # job_tickets has to be an Enumerable
24
+ # this block will run in a thread
25
+ Churner.new(job_ticket).churn
26
26
  ...
27
27
  end
28
28
 
29
+ Chantier does not provide any built-in IPC or inter-thread communication features - this should
30
+ stimulate you to write your tasks without them having to do IPC in the first place.
31
+
32
+
29
33
  == Contributing to chantier
30
34
 
31
35
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
data/chantier.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "chantier"
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Julik Tarkhanov"]
12
+ s.date = "2014-07-15"
13
+ s.description = " Process your jobs in parallel with a simple table of processes or threads "
14
+ s.email = "me@julik.nl"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "chantier.gemspec",
27
+ "lib/chantier.rb",
28
+ "lib/process_pool.rb",
29
+ "lib/thread_pool.rb",
30
+ "spec/process_pool_spec.rb",
31
+ "spec/spec_helper.rb",
32
+ "spec/thread_pool_spec.rb"
33
+ ]
34
+ s.homepage = "http://github.com/julik/chantier"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "2.0.3"
38
+ s.summary = "Dead-simple worker table based multiprocessing/multithreading"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rspec>, ["~> 2.9"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
48
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<rspec>, ["~> 2.9"])
51
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
54
+ s.add_dependency(%q<simplecov>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, ["~> 2.9"])
58
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
61
+ s.add_dependency(%q<simplecov>, [">= 0"])
62
+ end
63
+ end
64
+
data/lib/chantier.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Chantier
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  require_relative 'process_pool'
4
4
  require_relative 'thread_pool'
5
5
  end
data/lib/process_pool.rb CHANGED
@@ -27,17 +27,17 @@
27
27
  # Can be rewritten using Threads if operation on JVM/Rubinius will be feasible.
28
28
  class Chantier::ProcessPool
29
29
  # Kill the spawned processes after at most X seconds
30
- KILL_AFTER_SECONDS = 60 * 2
30
+ # KILL_AFTER_SECONDS = 60 * 2
31
31
 
32
32
  # http://linuxman.wikispaces.com/killing+me+softly
33
- TERMINATION_SIGNALS = %w( TERM HUP INT QUIT PIPE KILL )
33
+ # TERMINATION_SIGNALS = %w( TERM HUP INT QUIT PIPE KILL )
34
34
 
35
35
  # The manager uses loops in a few places. By doing a little sleep()
36
36
  # in those loops we can yield process control back to the OS which brings
37
37
  # the CPU usage of the managing process to small numbers. If you just do
38
38
  # a loop {} MRI will saturate a whole core and not let go off of it until
39
39
  # the loop returns.
40
- SCHEDULER_SLEEP_SECONDS = 0.05
40
+ SCHEDULER_SLEEP_SECONDS = (1.0 / 1000)
41
41
 
42
42
  def initialize(num_procs)
43
43
  raise "Need at least 1 slot, given #{num_procs.to_i}" unless num_procs.to_i > 0
@@ -100,17 +100,17 @@ class Chantier::ProcessPool
100
100
  # Dispatch the killer thread which kicks in after KILL_AFTER_SECONDS.
101
101
  # Note that we do not manage the @pids table here because once the process
102
102
  # gets terminated it will bounce back to the standard wait() above.
103
- Thread.new do
104
- sleep KILL_AFTER_SECONDS
105
- begin
106
- TERMINATION_SIGNALS.each do | sig |
107
- Process.kill(sig, task_pid)
108
- sleep 5 # Give it some time to react
109
- end
110
- rescue Errno::ESRCH
111
- # It has already quit, nothing to do
112
- end
113
- end
103
+ # Thread.new do
104
+ # sleep KILL_AFTER_SECONDS
105
+ # begin
106
+ # TERMINATION_SIGNALS.each do | sig |
107
+ # Process.kill(sig, task_pid)
108
+ # sleep 5 # Give it some time to react
109
+ # end
110
+ # rescue Errno::ESRCH
111
+ # # It has already quit, nothing to do
112
+ # end
113
+ # end
114
114
  end
115
115
 
116
116
  # Tells whether some processes are still churning
data/lib/thread_pool.rb CHANGED
@@ -32,7 +32,7 @@ class Chantier::ThreadPool
32
32
  # the CPU usage of the managing process to small numbers. If you just do
33
33
  # a loop {} MRI will saturate a whole core and not let go off of it until
34
34
  # the loop returns.
35
- SCHEDULER_SLEEP_SECONDS = 0.05
35
+ SCHEDULER_SLEEP_SECONDS = (1.0 / 500)
36
36
 
37
37
  def initialize(num_threads)
38
38
  raise "Need at least 1 slot, given #{num_threads.to_i}" unless num_threads.to_i > 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chantier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-13 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -94,6 +94,7 @@ files:
94
94
  - LICENSE.txt
95
95
  - README.rdoc
96
96
  - Rakefile
97
+ - chantier.gemspec
97
98
  - lib/chantier.rb
98
99
  - lib/process_pool.rb
99
100
  - lib/thread_pool.rb