Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rainbows! config file for use with EventMachine
# This is a configuration script for using Rainbows with EventMachine. I'm providing it incase somebody finds it useful. But honestly, you
# should stop using EventMachine and use threads instead. The ThreadPool version of this is also in my gist list, and I recommend taking a look at that instead.
Rainbows! do
name = 'yourappname'
use :EventMachine
client_max_body_size nil # This is set in nginx
# keepalive_timeout 1
case ENV['RACK_ENV'].to_sym
when :development
# This has weird issues with kqueue on OSX for me, so I use thin for development.
listen 9292
when :production
# Number of workers. I recommend one per CPU core to get full utilization.
worker_processes 4
# The number of simultaneous connections the server will accept.
worker_connections 1024
timeout 30
# I've been told the backlog here might be a problem if you're using a load balancer.
listen "unix:/var/run/yourcompany/#{name}.sock", :backlog => 4096
pid "/var/run/yourcompany/#{name}.pid"
stderr_path "/var/log/yourcompany/#{name}.log"
stdout_path "/var/log/yourcompany/#{name}.log"
# Hardcore performance tweaks, described here:
# This loads the app in master, and then forks workers. Kill with USR2 and it will do a graceful restart using the block proceeding.
preload_app true
before_fork do |server, worker|
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
# immediately start loading up a new version of itself (loaded with a new
# version of our app). When this new Unicorn is completely loaded
# it will begin spawning workers. The first worker spawned will check to
# see if an .oldbin pidfile exists. If so, this means we've just booted up
# a new Unicorn and need to tell the old one that it can now die. To do so
# we send it a QUIT.
# Using this method we get 0 downtime deploys.
old_pid = "/var/run/yourcompany/#{name}.pid.oldbin"
if File.exists?(old_pid) && != old_pid
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
Copy link

masterkain commented Feb 20, 2013

what's the reasoning behind discouraging using EM on Rainbows! ?

Copy link

sforce100 commented Aug 6, 2013

I want to ask the same question, and I can not choose . Have something advice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment