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 +4 -4
- data/Gemfile.lock +1 -3
- data/README.md +16 -19
- data/lib/parallax/collector.rb +6 -2
- data/lib/parallax/version.rb +1 -1
- data/lib/parallax.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b5ac6d394abaaa2b0f2b6634f0cb46a1e77584ae41d0a603dd46c96bd35b3c3
|
4
|
+
data.tar.gz: cc568d1e88bed4cb5f7d2f7708fe6cdf1203e4623c0541c4a0326c6d8c5771c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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
|
-
|
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
|
-
|
47
|
+
```ruby
|
48
|
+
numbers = (0..100).to_a
|
53
49
|
|
54
|
-
Parallax.execute
|
55
|
-
|
56
|
-
worker.
|
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
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
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.
|
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.
|
data/lib/parallax/collector.rb
CHANGED
@@ -14,8 +14,12 @@ module Parallax
|
|
14
14
|
@workers_data = []
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
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
|
|
data/lib/parallax/version.rb
CHANGED
data/lib/parallax.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|