qrpc 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,4 +1,15 @@
1
1
 
2
+ 0.2.2 (2011-02-13)
3
+ * subminor bug corrections
4
+ * beanstalkd queue now isn't emptified independently of the max
5
+ job settings
6
+ * max jobs set to 0 means, it's unlimited
7
+ * max job settings is now 0 by default
8
+ * minor performance optimizations
9
+
10
+ 0.2.1 (2011-02-06)
11
+ * missing UUID dependency in gem specification
12
+
2
13
  0.2.0 (2011-02-04)
3
14
  * client implemented
4
15
  * switch to em-jack
data/TODO.md CHANGED
@@ -1,3 +1,2 @@
1
- * general queue interface for ability to use more queue servers (starling, redis, ...)
1
+ * general queue interface for ability to use more queue servers (starling, sparrow, kestrel, stomp, AMQP...)
2
2
  * copyright headers to all files
3
- * add @since 0.1.0 to all methods which haven't later @since
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/lib/qrpc/client.rb CHANGED
@@ -218,7 +218,7 @@ module QRPC
218
218
 
219
219
  # Results pooler error handler
220
220
  @input_queue.on_error do |error|
221
- raise Exception::new("Beanstalk error: " << error.to_s)
221
+ raise ::Exception::new("Beanstalk error: " << error.to_s)
222
222
  end
223
223
 
224
224
  # Returns
@@ -33,17 +33,24 @@ module QRPC
33
33
 
34
34
  @max_jobs
35
35
 
36
+ ##
37
+ # Holds "full state" locking mutex.
38
+ #
39
+
40
+ @mutex
41
+
36
42
  ##
37
43
  # Constructor.
38
44
  #
39
45
 
40
- def initialize(max_jobs = 20)
46
+ def initialize(max_jobs = 0)
41
47
  @count = 0
42
48
  @queue = Depq::new
49
+ @mutex = Mutex::new
43
50
  @max_jobs = max_jobs
44
51
 
45
52
  if @max_jobs.nil?
46
- @max_jobs = 20
53
+ @max_jobs = 0
47
54
  end
48
55
  end
49
56
 
@@ -59,9 +66,10 @@ module QRPC
59
66
  return
60
67
  end
61
68
 
62
- if @count < @max_jobs
69
+ if self.available?
63
70
  self.process_next!
64
71
  @count += 1
72
+ self.regulate!
65
73
  end
66
74
  end
67
75
 
@@ -72,16 +80,55 @@ module QRPC
72
80
  def process_next!
73
81
  job = @queue.pop
74
82
  job.callback do
75
- if (@count < @max_jobs) and not @queue.empty?
83
+ if self.available? and not @queue.empty?
76
84
  self.process_next!
77
85
  else
78
86
  @count -= 1
87
+ self.regulate!
79
88
  end
80
89
  end
81
90
 
82
91
  job.process!
83
92
  end
84
93
 
94
+ ##
95
+ # Indicates free space is available in dispatcher.
96
+ #
97
+ # If block is given, locks to time space in dispatcher is
98
+ # available so works as synchronization primitive by this
99
+ # way.
100
+ #
101
+ # @overload available?
102
+ # @return [Boolean] +true+ if it is, +false+ in otherwise
103
+ # @overload available?(&block)
104
+ # @param [Proc] block synchronized block
105
+ #
106
+
107
+ def available?(&block)
108
+ if block.nil?
109
+ return ((@count < @max_jobs) or (@max_jobs == 0))
110
+ else
111
+ @mutex.synchronize(&block)
112
+ end
113
+ end
114
+
115
+
116
+ protected
117
+
118
+ ##
119
+ # Regulates by locking the dispatcher it if it's full.
120
+ #
121
+
122
+ def regulate!
123
+ if self.available?
124
+ if @mutex.locked?
125
+ @mutex.unlock
126
+ end
127
+ else
128
+ @mutex.try_lock
129
+ end
130
+ end
131
+
85
132
  end
86
133
  end
87
134
  end
data/lib/qrpc/server.rb CHANGED
@@ -180,9 +180,17 @@ module QRPC
180
180
 
181
181
  # Process input queue
182
182
  self.input_queue do |queue|
183
- queue.each_job do |job|
184
- self.process_job(job)
183
+ worker = Proc::new do
184
+ @dispatcher.available? do
185
+ queue.reserve do |job|
186
+ self.process_job(job)
187
+ job.delete()
188
+ worker.call()
189
+ end
190
+ end
185
191
  end
192
+
193
+ worker.call()
186
194
  end
187
195
  end
188
196
 
data/qrpc.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{qrpc}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Martin Kozák"]
12
- s.date = %q{2011-02-06}
12
+ s.date = %q{2011-02-13}
13
13
  s.email = %q{martinkozak@martinkozak.net}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  s.homepage = %q{http://github.com/martinkozak/qrpc}
44
44
  s.licenses = ["MIT"]
45
45
  s.require_paths = ["lib"]
46
- s.rubygems_version = %q{1.5.0}
46
+ s.rubygems_version = %q{1.5.2}
47
47
  s.summary = %q{Queued JSON-RPC client and server. Works as normal RPC server, but through queue interface, so allows highly scalable, distributed and asynchronous remote API implementation and fast data processing. It's based on eventmachine and beanstalkd, so it's fast and thread safe.}
48
48
 
49
49
  if s.respond_to? :specification_version then
data/test-client.rb CHANGED
@@ -7,19 +7,27 @@ require "eventmachine"
7
7
 
8
8
  EM::run do
9
9
  client = QRPC::Client::new QRPC::Locator::new :test
10
- puts client.inspect
11
-
12
- client.subtract(2, 3) do |i|
13
- puts i
14
- end
15
-
16
- client.subtract(3, 2) do |i|
17
- puts i
10
+ # puts client.inspect
11
+
12
+ # client.something_bad do |i|
13
+ # puts i
14
+ # end
15
+
16
+ count = 0
17
+
18
+ 10000.times do
19
+ client.subtract(2, 3) do |i|
20
+ # puts i
21
+ count += 1
22
+ if count >= 10000
23
+ EM::stop
24
+ end
25
+ end
18
26
  end
19
27
 
20
- client.something_bad do |i|
21
- puts i
22
- end
28
+ # client.subtract(3, 2) do |i|
29
+ # puts i
30
+ # end
23
31
  end
24
32
 
25
33
  =begin
data/test-server.rb CHANGED
@@ -10,4 +10,4 @@ end
10
10
 
11
11
  require "qrpc/server"
12
12
  server = QRPC::Server::new(Foo::new)
13
- server.listen! QRPC::Locator::new("test")
13
+ server.listen! QRPC::Locator::new("test"), :max_jobs => 0
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: qrpc
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Martin Koz\xC3\xA1k"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-06 00:00:00 +01:00
13
+ date: 2011-02-13 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -137,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- hash: 983554285799490160
140
+ hash: -1069714967795243013
141
141
  segments:
142
142
  - 0
143
143
  version: "0"
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  requirements: []
151
151
 
152
152
  rubyforge_project:
153
- rubygems_version: 1.5.0
153
+ rubygems_version: 1.5.2
154
154
  signing_key:
155
155
  specification_version: 3
156
156
  summary: Queued JSON-RPC client and server. Works as normal RPC server, but through queue interface, so allows highly scalable, distributed and asynchronous remote API implementation and fast data processing. It's based on eventmachine and beanstalkd, so it's fast and thread safe.