parallizer 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +2 -2
- data/README.md +121 -2
- data/VERSION +1 -1
- data/parallizer.gemspec +8 -8
- metadata +7 -7
data/Gemfile
CHANGED
@@ -5,8 +5,8 @@ source "http://rubygems.org"
|
|
5
5
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
gem "bundler"
|
9
|
-
gem "jeweler"
|
8
|
+
gem "bundler"
|
9
|
+
gem "jeweler"
|
10
10
|
|
11
11
|
gem "work_queue", ">= 0"
|
12
12
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,129 @@
|
|
1
|
-
# Parallizer - Execute your service layer in parallel
|
1
|
+
# Parallizer - Execute your service layer in parallel
|
2
|
+
|
3
|
+
Parallizer executes service methods in parallel, stores the method results, then creates a proxy with those results for your service. Your application then uses the short-lived service proxy (think of a single request for a web application) and executes your methods without again calling the underlying implementation. For applications that make considerable use of web service calls, Parallizer can give you a considerable performance boost.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install parallizer
|
2
8
|
|
3
9
|
## Examples
|
4
10
|
|
11
|
+
### Parallizing a service object
|
12
|
+
|
13
|
+
Here's an example service.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'net/http'
|
17
|
+
|
18
|
+
class SearchService
|
19
|
+
def search_result_for_foo
|
20
|
+
Net::HTTP.get('www.google.com', '/?q=foo')
|
21
|
+
end
|
22
|
+
|
23
|
+
def search_result_for_bar
|
24
|
+
Net::HTTP.get('www.google.com', '/?q=foo')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
$search_service = SearchService.new
|
29
|
+
```
|
30
|
+
|
31
|
+
Now create a Parallizer for that service and add all of the methods you intend to call. Then execute the service methods in parallel and return a service proxy that has the stored results of the method calls.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'parallizer'
|
35
|
+
|
36
|
+
parallizer = Parallizer.new($search_service)
|
37
|
+
parallizer.add.search_result_for_foo
|
38
|
+
parallizer.add.search_result_for_bar
|
39
|
+
search_service = parallizer.execute
|
40
|
+
```
|
41
|
+
|
42
|
+
Now use that service proxy in your application logic.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
puts search_service.search_result_for_foo
|
46
|
+
puts search_service.search_result_for_bar
|
47
|
+
```
|
48
|
+
|
49
|
+
Additional calls in your application logic will not result in an additional call to the underlying service.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
# Called twice, but no extra service call. (Be careful not to mutate the returned object!)
|
53
|
+
puts search_service.search_result_for_foo
|
54
|
+
puts search_service.search_result_for_foo
|
55
|
+
```
|
56
|
+
|
57
|
+
If there are additional methods on your service that were not parallized, you can still call them.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
puts search_service.search_result_for_foobar # does a Net::HTTP.get call
|
61
|
+
```
|
62
|
+
|
63
|
+
### Parallizing methods with parameters
|
64
|
+
|
65
|
+
Parallizing also works on service methods with parameters.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
require 'net/http'
|
69
|
+
require 'cgi'
|
70
|
+
|
71
|
+
class SearchService
|
72
|
+
def search_result(search_term)
|
73
|
+
Net::HTTP.get('www.google.com', "/?q=#{CGI.escape(search_term)}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
$search_service = SearchService.new
|
78
|
+
```
|
79
|
+
|
80
|
+
The parallel execution and proxy creation.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
require 'parallizer'
|
84
|
+
|
85
|
+
parallizer = Parallizer.new($search_service)
|
86
|
+
parallizer.add.search_result('foo')
|
87
|
+
parallizer.add.search_result('bar')
|
88
|
+
search_service = parallizer.execute
|
89
|
+
```
|
90
|
+
|
91
|
+
Using the service proxy in your application logic.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
puts search_service.search_result('foo') # returns stored value
|
95
|
+
puts search_service.search_result('bar') # returns stored value
|
96
|
+
puts search_service.search_result('foobar') # does a Net::HTTP.get call
|
97
|
+
```
|
98
|
+
|
99
|
+
|
100
|
+
### Parallizing class methods
|
101
|
+
|
102
|
+
You can even parallize class methods.
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
require 'net/http'
|
106
|
+
require 'parallizer'
|
107
|
+
|
108
|
+
parallizer = Parallizer.new(Net::HTTP)
|
109
|
+
parallizer.add.get('www.google.com', '/?q=foo')
|
110
|
+
parallizer.add.get('www.google.com', '/?q=bar')
|
111
|
+
http_service = parallizer.execute
|
112
|
+
```
|
113
|
+
|
114
|
+
Use the service proxy.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
# use your service proxy
|
118
|
+
http_service.get('www.google.com', '/?q=foo') # returns stored value
|
119
|
+
http_service.get('www.google.com', '/?q=bar') # returns stored value
|
120
|
+
http_service.get('www.google.com', '/?q=foobar') # does a Net::HTTP.get call
|
121
|
+
```
|
122
|
+
|
123
|
+
|
5
124
|
# Credits
|
6
125
|
|
7
|
-
|
126
|
+
[Parallizer](https://github.com/michaelgpearce/parallizer) is maintained by [Michael Pearce](http://github.com/michaelgpearce) and is funded by [BookRenter.com](http://www.bookrenter.com "BookRenter.com").
|
8
127
|
|
9
128
|
![BookRenter.com Logo](http://assets0.bookrenter.com/images/header/bookrenter_logo.gif "BookRenter.com")
|
10
129
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/parallizer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "parallizer"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Pearce"]
|
12
|
-
s.date = "2012-07-
|
12
|
+
s.date = "2012-07-30"
|
13
13
|
s.description = "Execute your service layer in parallel."
|
14
14
|
s.email = "michael.pearce@bookrenter.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,21 +42,21 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.specification_version = 3
|
43
43
|
|
44
44
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
-
s.add_runtime_dependency(%q<bundler>, [">=
|
46
|
-
s.add_runtime_dependency(%q<jeweler>, [">=
|
45
|
+
s.add_runtime_dependency(%q<bundler>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<jeweler>, [">= 0"])
|
47
47
|
s.add_runtime_dependency(%q<work_queue>, [">= 0"])
|
48
48
|
s.add_runtime_dependency(%q<work_queue>, [">= 0"])
|
49
49
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
50
50
|
else
|
51
|
-
s.add_dependency(%q<bundler>, [">=
|
52
|
-
s.add_dependency(%q<jeweler>, [">=
|
51
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
52
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
53
53
|
s.add_dependency(%q<work_queue>, [">= 0"])
|
54
54
|
s.add_dependency(%q<work_queue>, [">= 0"])
|
55
55
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
56
56
|
end
|
57
57
|
else
|
58
|
-
s.add_dependency(%q<bundler>, [">=
|
59
|
-
s.add_dependency(%q<jeweler>, [">=
|
58
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
59
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
60
60
|
s.add_dependency(%q<work_queue>, [">= 0"])
|
61
61
|
s.add_dependency(%q<work_queue>, [">= 0"])
|
62
62
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: jeweler
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: '0'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: work_queue
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
segments:
|
130
130
|
- 0
|
131
|
-
hash: -
|
131
|
+
hash: -1557478882810554134
|
132
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
133
|
none: false
|
134
134
|
requirements:
|