parallax 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cae7c981eb874ee20e40f328564c54396b01ba96f4c6690ed413c90ad944a308
4
- data.tar.gz: a39524c02835452a762cc05a6dd72d334f45a77ed6d4da13f91f83f49c9f4a31
3
+ metadata.gz: 1b5ac6d394abaaa2b0f2b6634f0cb46a1e77584ae41d0a603dd46c96bd35b3c3
4
+ data.tar.gz: cc568d1e88bed4cb5f7d2f7708fe6cdf1203e4623c0541c4a0326c6d8c5771c5
5
5
  SHA512:
6
- metadata.gz: 683dafee698a6ff5777161e942d8c0ebe692e185de551f15d98142bc59808c95981bf90d9fcaf4e61576232936da8158596a56e25eff79940172c9cca93bbc74
7
- data.tar.gz: d309857b1a699cedc9f680f5d13220c8b0ab6b9079de499b9038f9b38fe92e4f627eb78bee3d3fab7c2c89aefdb0f149adb676974a40cb1eb61772083692a46f
6
+ metadata.gz: a72b7b5fb0d24365f359ce534b0c5feba903a8e534a994c509a0f2ff13fac449023990903e6f5dcd8ac85dc6bb2d358bddfd7f40c5f3f0058b2b16d79288bdf1
7
+ data.tar.gz: 126f94e0441ce1bbc4acbbc86488b4f0df19bfa537c2afaca0ec0b6dd1d51ae7eb3b06d3cfd8586a3b40364ff7c54370abba4a89cdf6c9220d39575c7ddc7cfd
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parallax (0.1.0)
4
+ parallax (0.1.1)
5
5
  activesupport
6
- msgpack
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
@@ -18,7 +17,6 @@ GEM
18
17
  i18n (1.1.1)
19
18
  concurrent-ruby (~> 1.0)
20
19
  minitest (5.11.3)
21
- msgpack (1.2.4)
22
20
  rainbow (3.0.0)
23
21
  rake (10.5.0)
24
22
  rspec (3.8.0)
data/README.md CHANGED
@@ -29,7 +29,7 @@ array = [ 'running', 'code', 'in', 'parallel' ]
29
29
 
30
30
  Parallax.execute array do |worker, array_chunk|
31
31
  array_chunk.each do |element|
32
- worker.send :log, "[#{worker.index}] #{element}"
32
+ worker.log "[#{worker.index}] #{element}"
33
33
  end
34
34
  end
35
35
 
@@ -40,34 +40,31 @@ end
40
40
  # [2] in
41
41
  ```
42
42
 
43
- If you need inter-process communication, this can be done by calling `worker.send` and passing a list of arguments. The args are serialized and passed via IO pipe to a `collector` object, which is by default an instance of `Parallax::Collector` class. The collector then parses the args and treats them like a method call where the first arg is the name of the method. In the example above, the collectors calls the `log` method which prints the second arg. Of course you can specify your own collector, as long as it responds to a `collect(*args)` method.
43
+ If you need inter-process communication, this can be done by calling `worker.send` and passing a list of arguments. The args are serialized and passed via IO pipe to a `collector` object, which is by default an instance of `Parallax::Collector` class. The collector then parses the args and treats them like a method call where the first arg is the name of the method. In the example above, the collectors calls the `log` method which prints the second arg.
44
44
 
45
- ```ruby
46
- class MyCollector
47
- def receive(*args)
48
- puts "Custom collector is receiving: #{args.inspect}"
49
- end
50
- end
45
+ The collector object is returned by the `Parallax.execute` method, so if you need to store each worker processed data you can use the `worker.store` method or implement it in your own custom collector. For example:
51
46
 
52
- array = [ 'running', 'code', 'in', 'parallel' ]
47
+ ```ruby
48
+ numbers = (0..100).to_a
53
49
 
54
- Parallax.execute array, collector: MyCollector do |worker, array_chunk|
55
- array_chunk.each do |element|
56
- worker.send "[#{worker.index}] #{element}"
50
+ collector = Parallax.execute numbers, do |worker, numbers_chunk|
51
+ numbers_chunk.each do |number|
52
+ worker.store number * 2
57
53
  end
58
54
  end
59
55
 
56
+ puts collector.workers_data.inspect
57
+
60
58
  # Example output with 4 cores:
61
- # Custom collector is receiving: ["[1] code"]
62
- # Custom collector is receiving: ["[3] parallel"]
63
- # Custom collector is receiving: ["[0] running"]
64
- # Custom collector is receiving: ["[2] in"]
59
+ # [ [2018-12-04 08:22:06 +0100, 0, 0],
60
+ # [2018-12-04 08:22:06 +0100, 3, 152],
61
+ # [2018-12-04 08:22:06 +0100, 1, 52],
62
+ # [2018-12-04 08:22:06 +0100, 2, 102],
63
+ # ...
65
64
  ```
66
65
 
67
- The collector object is returned by the `Parallax.execute` method, so if you need to store each worker processed data you can use the `worker.store` method or implement it in your own custom collector.
68
-
69
66
  Other options you can pass to execute are:
70
- * `processes`: the number of processes in which parallelize the execution. Defaults to `Etc.nprocessors` (which is equal to the number of cores of the current running machine).
67
+ * `processes`: the number of processes in which parallelize the execution. Defaults to `Etc.nprocessors` (which is equal to the number of cores of the current running machine).
71
68
 
72
69
  Methods available for a `worker` object, which are collected in the `collector` object:
73
70
  * `log(message)`: prints a message in stdout.
@@ -14,8 +14,12 @@ module Parallax
14
14
  @workers_data = []
15
15
  end
16
16
 
17
- def collect
18
- worker_index, method, *arguments = eval(@receiving_stream.gets.chomp)
17
+ def receive
18
+ self.collect @receiving_stream.gets.chomp
19
+ end
20
+
21
+ def collect(message)
22
+ worker_index, method, *arguments = eval(message)
19
23
  self.send method, worker_index, *arguments
20
24
  end
21
25
 
@@ -1,3 +1,3 @@
1
1
  module Parallax
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/parallax.rb CHANGED
@@ -35,7 +35,7 @@ module Parallax
35
35
  end
36
36
 
37
37
  until collector.all_workers_terminated?
38
- collector.collect
38
+ collector.receive
39
39
  end
40
40
  collector.close
41
41
  collector
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Ballardin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-03 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport