• Stars
    star
    244
  • Rank 159,957 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 14 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rack middleware to execute each request in a Fiber

The new homepage is https://github.com/alebsack/rack-fiber_pool

rack-fiber_pool

A Rack middleware component which runs each request in a Fiber from a pool of Fibers.

Requirements

  • Ruby 1.9
  • EventMachine-based server (e.g. thin or rainbows)

Usage

Add a require and use statement to your Rack app. See example/app.rb for a simple Sinatra app which illustrates proper usage. In general, you want the FiberPool to be inserted as early as possible in the middleware pipeline.

Options

You may fix the pool size, otherwise it defaults to 100:

use Rack::FiberPool, :size => 25

All exceptions raised by request handled within a fiber are rescued, by default returning a 500 with no body content. You may customize exceptions rescuing by providing a Proc object conforming to Rack's API:

rescue_exception = Proc.new { |env, exception| [503, {}, exception.message] }
use Rack::FiberPool, :rescue_exception => rescue_exception

Rails

You can see your app's current pipeline of Rack middleware using:

rake middleware

Add Rack::FiberPool to your middleware in config/environment.rb:

require 'rack/fiber_pool'
Rails::Initializer.run do |config|
  config.middleware.use Rack::FiberPool
  config.threadsafe!
end

If you do experience odd issues, make sure it appears as early in the pipeline as possible. Anything 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.

You can explicitly place the FiberPool like so:

ActionController::Dispatcher.middleware.insert_before ActionController::Session::CookieStore, Rack::FiberPool

Thanks to

Eric Wong - for adding explicit support for Rack::FiberPool to rainbows.

Changes

0.9.3 - fix incompatibility with sinatra streaming, new maintainer (alebsack)

Author

Mike Perham, Twitter, Github, mperham AT gmail.com.

More Repositories

1

sidekiq

Simple, efficient background processing for Ruby
Ruby
12,059
star
2

inspeqtor

Monitor your application infrastructure!
Go
1,659
star
3

connection_pool

Generic connection pooling for Ruby
Ruby
1,596
star
4

girl_friday

Have a task you want to get done but don't want to do it yourself? Give it to girl_friday!
Ruby
606
star
5

bayes_motel

Multi-variate Bayesian classification engine
Ruby
190
star
6

evented

Your source for event-drivenness!
Ruby
172
star
7

phat

Asynchronous Rails!
Ruby
95
star
8

em_postgresql

ActiveRecord driver for Postgresql with EventMachine
Ruby
66
star
9

inspeqtor-pro

Modern service monitoring, business edition.
Go
52
star
10

kuiq

Sidekiq desktop app
Ruby
48
star
11

politics

Utilities and Algorithms for Distributed Processing.
Ruby
47
star
12

qanat

Fiber-based, highly concurrent MQ processor for Ruby
Ruby
39
star
13

chrono.js

Application metrics, webscale!
JavaScript
22
star
14

bloaty_mcbloatface

"Oh my, you've put on some weight..."
Ruby
12
star
15

phony_baloney

Create fake servers for testing purposes
Ruby
10
star
16

acting_lessons

Abusing Rubinius's Actors for fun and profit
Ruby
10
star
17

gobox

How to use Golang's NaCl crypto API
Go
10
star
18

breakout

The classic Breakout game
Ruby
9
star
19

dotfiles

my dotfiles
Shell
7
star
20

switch_redis

Ruby
7
star
21

discontent

The forum for terrible people
Ruby
7
star
22

blog

My blargh!
HTML
7
star
23

sidekiq-websockets

Ruby
7
star
24

dotenv

Load contents of .env into child processes
Go
6
star
25

resque-client.go

Resque worker/client, written in Go
Go
6
star
26

contribsys.com

contribsys.com
CSS
5
star
27

edistuff

EDI parser and generation code
Java
5
star
28

queso

Query anything!
Ruby
5
star
29

gem_dir

Adds the 'gem dir' command to RubyGems to display the root directory of a given gem.
Ruby
4
star
30

tracknowledge

Race Tracks Galore!
Ruby
4
star
31

aoc2016

Advent of Code 2016
Ruby
4
star
32

right_aws

RightScale's right_aws 1.10.0 gem with fixes
Ruby
3
star
33

minesweeper

Minesweeper for MacRuby
3
star
34

docdb_shootout

Document-oriented database comparision
Ruby
3
star
35

news_flash

Show your users the latest news
Ruby
2
star
36

slice

My slice configuration
Ruby
1
star
37

perham.net

HTML
1
star
38

docs

The open-source repo for docs.github.com
JavaScript
1
star