Code Monkey home page Code Monkey logo

rack-fiber_pool's Introduction

rack-fiber_pool

Dependency Status Coverage Status Build Status Code Climate

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) 1.0.0.beta.1 - Refactor, maintaining compatibility

Authors

Adam Lebsack, Github, alebsack AT gmail.com.

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

rack-fiber_pool's People

Contributors

alebsack avatar francois2metz avatar mperham avatar smparkes avatar zquestz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.