jruby-rack-worker 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright (c) 2010-2012 Karol Bucek
189
+ Copyright (c) 2010-2013 Karol Bucek
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Thread based workers on top of [jruby-rack](http://github.com/jruby/jruby-rack).
4
4
 
5
- With out of the box thread-safe [JRuby](http://jruby.org) "adapters" for:
5
+ With out of the box thread-safe [JRuby](http://jruby.org) "adapters" for:
6
6
 
7
- * [Resque](http://github.com/defunkt/resque) (>= 1.20.0)
7
+ * [Resque](http://github.com/defunkt/resque) (>= 1.20.0, ~> 2.0.0 [master])
8
8
  * [Delayed::Job](http://github.com/collectiveidea/delayed_job) (~> 2.1, >= 3.0)
9
9
  * [Navvy](http://github.com/jeffkreeftmeijer/navvy) (not-maintained)
10
10
 
@@ -14,25 +14,25 @@ With out of the box thread-safe [JRuby](http://jruby.org) "adapters" for:
14
14
 
15
15
  ## Motivation
16
16
 
17
- Ruby attempts to stay pretty close to UNIX and most popular workers have been
18
- modeled the "spawn a background process" way. [JRuby](http://jruby.org) brings
19
- Java to the table, where "Young Java Knights" are thought to use threads
20
- whenever in a need to compute something parallel while serving requests.
17
+ Ruby attempts to stay pretty close to UNIX and most popular workers have been
18
+ modeled the "spawn a background process" way. [JRuby](http://jruby.org) brings
19
+ Java to the table, where "Young Java Knights" are taught to use threads
20
+ whenever in a need to compute something in parallel with serving requests.
21
21
 
22
22
  There's no right or wrong way of doing this. If you do expect chaos like Resque
23
- proclaims - have long running jobs that consume a lot of memory they have trouble
23
+ proclaims - have long running jobs that consume a lot of memory they have trouble
24
24
  releasing (e.g. due C extensions) run a separate process for sure.
25
- But otherwise (after all C exts usually have a native Java alternative on JRuby)
26
- having predictable thread-safely written workers, one should be fine with
25
+ But otherwise (after all C exts usually have a native Java alternative on JRuby)
26
+ having predictable thread-safely written workers, one should be fine with
27
27
  running them concurrently as part of the application in a (daemon) thread.
28
28
 
29
29
  This does have the advantage of keeping the deployment simple and saving some
30
- precious memory (most notably with `threadsafe!` mode) that would have been
31
- eaten by the separate process. Besides, your application might warm up faster
30
+ precious memory (most notably with `threadsafe!` mode) that would have been
31
+ eaten by the separate process. Besides, your application might warm up faster
32
32
  and start benefiting from JRuby's runtime optimalizations slightly sooner ...
33
33
 
34
- On the other hand your jobs should be fairly simple and complete "fast" (in a
35
- rate of seconds rather than several minutes or hours) as they will live and
34
+ On the other hand your jobs should be fairly simple and complete "fast" (in a
35
+ rate of seconds rather than several minutes or hours) as they will live and
36
36
  restart with the lifecycle of the deployed application and application server.
37
37
 
38
38
 
@@ -45,46 +45,64 @@ Configure your worker in **web.xml**, you will need to add a context listener
45
45
  that will start (daemon) threads when your application boots and a script to be
46
46
  executed (should be an "endless" loop-ing script). Sample configuration :
47
47
 
48
- <context-param>
49
- <param-name>jruby.worker.script</param-name>
50
- <param-value>
51
- <!-- any script with an end-less loop : ->
52
- require 'delayed/jruby_worker'
53
- Delayed::JRubyWorker.new.start
54
- </param-value>
55
- </context-param>
56
-
57
- <listener>
58
- <listener-class>org.kares.jruby.rack.WorkerContextListener</listener-class>
59
- </listener>
60
-
61
- The `WorkerContextListener` needs to be executed (and thus configured) after the
62
- `RailsServletContextListener`/`RackServletContextListener` as it expects the
48
+ ```xml
49
+ <context-param>
50
+ <param-name>jruby.worker.script</param-name>
51
+ <param-value>
52
+ <!-- any script with an end-less loop : ->
53
+ require 'delayed/jruby_worker'
54
+ Delayed::JRubyWorker.new.start
55
+ </param-value>
56
+ </context-param>
57
+
58
+ <listener>
59
+ <listener-class>org.kares.jruby.rack.WorkerContextListener</listener-class>
60
+ </listener>
61
+ ```
62
+
63
+ The `WorkerContextListener` needs to be executed (and thus configured) after the
64
+ `RailsServletContextListener`/`RackServletContextListener` as it expects the
63
65
  JRuby-Rack environment to be booter and available.
64
66
 
65
67
  For built-in worker support (if you're happy with the defaults) simply specify
66
68
  the **jruby.worker** context parameter (optionally with custom params supported
67
69
  by the worker) e.g. :
68
70
 
69
- <context-param>
70
- <param-name>jruby.worker</param-name>
71
- <param-value>resque</param-value>
72
- </context-param>
73
- <context-param>
74
- <param-name>QUEUES</param-name>
75
- <param-value>mails,posts</param-value>
76
- </context-param>
77
- <context-param>
78
- <param-name>INTERVAL</param-name>
79
- <param-value>2.5</param-value>
80
- </context-param>
81
-
82
- <listener>
83
- <listener-class>org.kares.jruby.rack.WorkerContextListener</listener-class>
84
- </listener>
71
+ ```xml
72
+ <context-param>
73
+ <param-name>jruby.worker</param-name>
74
+ <param-value>resque</param-value>
75
+ </context-param>
76
+ <context-param>
77
+ <param-name>QUEUES</param-name>
78
+ <param-value>mails,posts</param-value>
79
+ </context-param>
80
+ <context-param>
81
+ <param-name>INTERVAL</param-name>
82
+ <param-value>2.5</param-value>
83
+ </context-param>
84
+
85
+ <listener>
86
+ <listener-class>org.kares.jruby.rack.WorkerContextListener</listener-class>
87
+ </listener>
88
+ ```
85
89
 
86
90
  Sample deployment descriptor including optional parameters:
87
- [web.xml](/kares/jruby-rack-worker/blob/master/src/test/resources/sample.web.xml).
91
+ [web.xml](src/test/resources/sample.web.xml).
92
+
93
+ ### Threads
94
+
95
+ Number of worker threads as well as their priorities can be configured (by
96
+ default a single worker thread is started with the default NORM priority) :
97
+
98
+ - *jruby.worker.thread.count* please be sure you do not start too many threads,
99
+ consider tuning your worker settings if possible first e.g. for DJ/Resque the
100
+ sleep interval if you feel like the worker is not performing enough work.
101
+ - *jruby.worker.thread.priority* maps to standard (Java) thread priority which
102
+ is a value <MIN, MAX> where MIN == 1 and MAX == 10 (the NORM priority is 5),
103
+ this is useful e.g. if you're load gets high (lot of request serving threads)
104
+ and you do care about requests more than about executing worker code you might
105
+ consider decreasing the priority (by 1).
88
106
 
89
107
  ### Warbler
90
108
 
@@ -145,13 +163,16 @@ Warbler checks for a *config/web.xml.erb* thus configure the worker there, e.g.
145
163
  </web-app>
146
164
  ```
147
165
 
148
- If you're deploying a Rails application on JRuby it's highly **recommended** to
149
- uncomment `config.threadsafe!`. Otherwise, if unsure or you're code is not
150
- thread-safe yet you'll end up polling several JRuby runtimes in a single process,
151
- in this case however each worker thread will use (block) an application runtime
152
- from the pool (consider it while setting
166
+ If you're deploying a Rails application on JRuby it's highly **recommended** to
167
+ uncomment `config.threadsafe!`. Otherwise, if unsure or you're code is not
168
+ thread-safe yet you'll end up polling several JRuby runtimes in a single process,
169
+ in this case however each worker thread will use (block) an application runtime
170
+ from the pool (consider it while setting
153
171
  `jruby.min.runtimes` and `jruby.max.runtimes` parameters).
154
172
 
173
+ ### Trinidad
174
+
175
+ Trinidad provides you with an [extension][1] so you do not have to deal with XML.
155
176
 
156
177
  ### Custom Workers
157
178
 
@@ -170,7 +191,7 @@ got a worker spawning script (e.g. a rake task) start there to write the worker
170
191
  class variables are not being used to store worker state)
171
192
 
172
193
  * refactor your worker's exit code from a (process oriented) signal based `trap`
173
- to an `at_exit` hook - which respects the JRuby environment your workers are
194
+ to an `at_exit` hook - which respects the JRuby environment your workers are
174
195
  going to be running in
175
196
 
176
197
  Keep in mind that if you do configure to use multiple threads the script will be
@@ -180,8 +201,8 @@ a separate file that you'll require from the script.
180
201
  See the [Delayed::Job](/kares/jruby-rack-worker/tree/master/src/main/ruby/delayed)
181
202
  JRuby "adapted" worker code for an inspiration.
182
203
 
183
- If you'd like to specify custom parameters you can do so in the deployment
184
- descriptor as context init parameters or as java system properties, use the
204
+ If you'd like to specify custom parameters you can do so in the deployment
205
+ descriptor as context init parameters or as java system properties, use the
185
206
  following code to obtain them :
186
207
 
187
208
  ```ruby
@@ -228,7 +249,8 @@ Build the gem (includes the .jar packaged) :
228
249
 
229
250
  ## Copyright
230
251
 
231
- Copyright (c) 2012 [Karol Bucek](https://github.com/kares).
252
+ Copyright (c) 2013 [Karol Bucek](https://github.com/kares).
232
253
  See LICENSE (http://www.apache.org/licenses/LICENSE-2.0) for details.
233
254
 
234
- [0]: https://secure.travis-ci.org/kares/jruby-rack-worker.png
255
+ [0]: https://secure.travis-ci.org/kares/jruby-rack-worker.png
256
+ [1]: https://github.com/trinidad/trinidad_worker_extension
@@ -1,7 +1,7 @@
1
1
  module JRuby
2
2
  module Rack
3
3
  module Worker
4
- VERSION = '0.9.1'
4
+ VERSION = '0.10.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,75 +1,72 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jruby-rack-worker
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.9.1
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.10.0
6
6
  platform: ruby
7
- authors:
8
- - Karol Bucek
9
- autorequire:
7
+ authors:
8
+ - Karol Bucek
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2013-01-07 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: jruby-rack
17
- version_requirements: &id001 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.1.10
23
- requirement: *id001
24
- prerelease: false
25
- type: :runtime
12
+ date: 2013-06-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jruby-rack
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.1.10
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.10
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
26
30
  description: Implements a thread based worker pattern on top of JRuby-Rack. Useful if you'd like to run background workers within your (deployed) web-application (concurrently in 'native' threads) instead of using separate daemon processes. Provides (thread-safe) implementations for popular worker libraries such as Resque and Delayed::Job, but one can easily write their own 'daemon' scripts as well.
27
- email:
28
- - self@kares.org
31
+ email:
32
+ - self@kares.org
29
33
  executables: []
30
-
31
34
  extensions: []
32
-
33
35
  extra_rdoc_files: []
34
-
35
- files:
36
- - README.md
37
- - LICENSE
38
- - lib/jruby-rack-worker_0.9.1.jar
39
- - lib/jruby_rack_worker.rb
40
- - lib/jruby/rack/worker.rb
41
- - lib/jruby/rack/worker/env.rb
42
- - lib/jruby/rack/worker/logger.rb
43
- - lib/jruby/rack/worker/version.rb
36
+ files:
37
+ - LICENSE
38
+ - README.md
39
+ - lib/jruby-rack-worker_0.10.0.jar
40
+ - lib/jruby/rack/worker.rb
41
+ - lib/jruby/rack/worker/env.rb
42
+ - lib/jruby/rack/worker/logger.rb
43
+ - lib/jruby/rack/worker/version.rb
44
+ - lib/jruby_rack_worker.rb
44
45
  homepage: http://github.com/kares/jruby-rack-worker
45
46
  licenses: []
46
-
47
- post_install_message:
47
+ post_install_message:
48
48
  rdoc_options: []
49
-
50
- require_paths:
51
- - lib
52
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ hash: 2
58
+ version: '0'
53
59
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 2
58
- segments:
59
- - 0
60
- version: "0"
61
- required_rubygems_version: !ruby/object:Gem::Requirement
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
62
65
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
67
66
  requirements: []
68
-
69
- rubyforge_project: "[none]"
67
+ rubyforge_project: '[none]'
70
68
  rubygems_version: 1.8.24
71
- signing_key:
69
+ signing_key:
72
70
  specification_version: 3
73
71
  summary: Threaded Workers with JRuby-Rack
74
72
  test_files: []
75
-