Book Image

Heroku Cookbook

By : Mike Coutermarsh
Book Image

Heroku Cookbook

By: Mike Coutermarsh

Overview of this book

Heroku is a Platform as a Service that enables developers to rapidly deploy and scale their web applications. Heroku is designed for developer happiness, freeing developers from doing system administrative tasks such as configuring servers and setting up load balancers. Developers are able to focus on what they do best, building web applications, while leaving the details of deployment and scaling to the experts at Heroku. This practical guide is packed with step-by-step solutions to problems faced by every production-level web application hosted on Heroku. You'll quickly get comfortable with managing your Heroku applications from the command line and then learn everything you need to know to deploy and administer production-level web applications.
Table of Contents (17 chapters)
Heroku Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Aborting long requests with Rack::Timeout


A pile up of long running requests is a sure way to bring our entire application to a screaming halt. When a web request to a Heroku application takes longer than 30 seconds to respond, Heroku will terminate the request and return an H12 error to the user. The problem with this is that this does not actually stop the request from being processed by our dynos. Even though the user will never receive a response, our dynos will keep working on the request until it is complete. This is an obvious waste of resources, but we can easily avoid this by adding Rack::Timeout to our applications.

How to do it…

To set up Rack::Timeout, we'll need to add a gem to our Gemfile and an initializer to our Rails app. Let's fire up a terminal and navigate to our blogger-app directory by performing the following steps:

  1. We can start by adding rack-timeout to our Gemfile:

    gem 'rack-timeout'
  2. Then, install the gem by running bundle install:

    $ bundle install
    
  3. Now, we'll need to...