rack-fiber_pool 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Mike Perham
1
+ Copyright (c) 2011 Mike Perham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -7,15 +7,46 @@ Requirements
7
7
  ==============
8
8
 
9
9
  * Ruby 1.9
10
- * thin 1.2.7
10
+ * EventMachine-based server (e.g. thin or rainbows)
11
11
 
12
12
  Usage
13
13
  =======
14
14
 
15
15
  Add a require and use statement to your Rack app. See example/app.rb for a simple Sinatra app
16
- which illustrates proper usage.
16
+ which illustrates proper usage. In general, you want the FiberPool to be inserted as early as
17
+ possible in the middleware pipeline.
18
+
19
+
20
+ Rails
21
+ ========
22
+
23
+ You can see your app's current pipeline of Rack middleware using:
24
+
25
+ rake middleware
26
+
27
+ Add Rack::FiberPool to your middleware in `config/environment.rb`:
28
+
29
+ require 'rack/fiber_pool'
30
+ Rails::Initializer.run do |config|
31
+ config.middleware.use Rack::FiberPool
32
+ config.threadsafe!
33
+ end
34
+
35
+ If you do experience odd issues, make sure it appears as early in the pipeline as possible. Anything
36
+ that sets/gets thread local variables (like the Rails' session) or performs I/O should be later in the pipeline. For example, ActionController::Session::CookieStore does not work if it appears before Rack::FiberPool.
37
+
38
+ You can explicitly place the FiberPool like so:
39
+
40
+ ActionController::Dispatcher.middleware.insert_before ActionController::Session::CookieStore, Rack::FiberPool
41
+
42
+
43
+ Thanks to
44
+ ==========
45
+
46
+ Eric Wong - for adding explicit support for Rack::FiberPool to rainbows.
47
+
17
48
 
18
49
  Author
19
50
  =========
20
51
 
21
- Mike Perham, http://twitter.com/mperham, http://github.com/mperham, mperham AT gmail.com.
52
+ Mike Perham, [Twitter](http://twitter.com/mperham), [Github](http://github.com/mperham), mperham AT gmail.com.
data/Rakefile CHANGED
@@ -1,52 +1,8 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "rack-fiber_pool"
8
- gem.summary = %Q{Rack middleware to run each request within a Fiber}
9
- gem.email = "mperham@gmail.com"
10
- gem.homepage = "http://github.com/mperham/rack-fiber_pool"
11
- gem.authors = ["Mike Perham"]
12
- gem.add_development_dependency "shoulda", ">= 0"
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
- end
15
- Jeweler::GemcutterTasks.new
16
- rescue LoadError
17
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
- end
19
-
20
1
  require 'rake/testtask'
21
2
  Rake::TestTask.new(:test) do |test|
22
- test.libs << 'lib' << 'test'
3
+ test.libs << 'test'
23
4
  test.pattern = 'test/**/test_*.rb'
24
5
  test.verbose = true
25
6
  end
26
7
 
27
- begin
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |test|
30
- test.libs << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
- rescue LoadError
35
- task :rcov do
36
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
- end
38
- end
39
-
40
- task :test => :check_dependencies
41
-
42
8
  task :default => :test
43
-
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
-
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "rack-fiber_pool #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
data/example/app.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  raise LoadError, "Ruby 1.9.1 only" if RUBY_VERSION < '1.9.1'
2
2
 
3
- require 'rubygems'
4
3
  require 'sinatra/base'
5
4
  require 'fiber'
6
5
 
data/lib/fiber_pool.rb CHANGED
@@ -55,7 +55,7 @@ class FiberPool
55
55
  block = @queue.shift
56
56
  else
57
57
  @busy_fibers.delete(Fiber.current.object_id)
58
- @fibers << Fiber.current
58
+ @fibers.unshift Fiber.current
59
59
  block = Fiber.yield
60
60
  end
61
61
  end
@@ -1,13 +1,16 @@
1
1
  require 'fiber_pool'
2
2
 
3
3
  module Rack
4
- # Run each request in a Fiber. This FiberPool is
5
- # provided by em_postgresql. Should probably split
6
- # this dependency out.
7
4
  class FiberPool
8
- def initialize(app)
5
+ VERSION = '0.9.1'
6
+ SIZE = 100
7
+
8
+ # The size of the pool is configurable:
9
+ #
10
+ # use Rack::FiberPool, :size => 25
11
+ def initialize(app, options={})
9
12
  @app = app
10
- @fiber_pool = ::FiberPool.new
13
+ @fiber_pool = ::FiberPool.new(options[:size] || SIZE)
11
14
  yield @fiber_pool if block_given?
12
15
  end
13
16
 
data/test/helper.rb CHANGED
@@ -1,10 +1,4 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
1
+ require 'minitest/autorun'
2
+ require 'rack'
3
+ require 'rack/mock'
7
4
  require 'rack/fiber_pool'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,5 +1,28 @@
1
1
  require 'helper'
2
2
 
3
- class TestRackFiberPool < Test::Unit::TestCase
4
- # An exercise left to the reader
3
+ class TestRackFiberPool < MiniTest::Unit::TestCase
4
+
5
+ def test_usage
6
+ app = TestApp.new
7
+ catch :async do
8
+ res = Rack::MockRequest.new(Rack::FiberPool.new(app)).get("/")
9
+ end
10
+ assert_equal [200, {"Content-Type"=>"text/plain"}, ["Hello world!"]], app.result
11
+ end
12
+
13
+ def test_size
14
+ app = TestApp.new
15
+ catch :async do
16
+ res = Rack::MockRequest.new(Rack::FiberPool.new(app, :size => 5)).get("/")
17
+ end
18
+ assert_equal [200, {"Content-Type"=>"text/plain"}, ["Hello world!"]], app.result
19
+ end
20
+
21
+ class TestApp
22
+ attr_accessor :result
23
+ def call(env)
24
+ env['async.callback'] = proc { |result| @result = result }
25
+ [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
26
+ end
27
+ end
5
28
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 0
9
- version: 0.9.0
8
+ - 1
9
+ version: 0.9.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mike Perham
@@ -14,35 +14,22 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-03 00:00:00 -05:00
17
+ date: 2011-01-14 00:00:00 -08:00
18
18
  default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: shoulda
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :development
31
- version_requirements: *id001
32
- description:
19
+ dependencies: []
20
+
21
+ description: Rack middleware to run each request within a Fiber
33
22
  email: mperham@gmail.com
34
23
  executables: []
35
24
 
36
25
  extensions: []
37
26
 
38
- extra_rdoc_files:
39
- - LICENSE
40
- - README.md
27
+ extra_rdoc_files: []
28
+
41
29
  files:
42
30
  - LICENSE
43
31
  - README.md
44
32
  - Rakefile
45
- - VERSION
46
33
  - example/app.rb
47
34
  - lib/fiber_pool.rb
48
35
  - lib/rack/fiber_pool.rb
@@ -58,6 +45,7 @@ rdoc_options:
58
45
  require_paths:
59
46
  - lib
60
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
61
49
  requirements:
62
50
  - - ">="
63
51
  - !ruby/object:Gem::Version
@@ -65,6 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
53
  - 0
66
54
  version: "0"
67
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
68
57
  requirements:
69
58
  - - ">="
70
59
  - !ruby/object:Gem::Version
@@ -74,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
63
  requirements: []
75
64
 
76
65
  rubyforge_project:
77
- rubygems_version: 1.3.6
66
+ rubygems_version: 1.3.7
78
67
  signing_key:
79
68
  specification_version: 3
80
69
  summary: Rack middleware to run each request within a Fiber
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.9.0