Skip to content

Instantly share code, notes, and snippets.

View andrewle's full-sized avatar

Andrew Le andrewle

View GitHub Profile
@joewiz
joewiz / post-mortem.md
Last active September 3, 2023 11:57
Recovery from nginx "Too many open files" error on Amazon AWS Linux

On Tue Oct 27, 2015, history.state.gov began buckling under load, intermittently issuing 500 errors. Nginx's error log was sprinkled with the following errors:

2015/10/27 21:48:36 [crit] 2475#0: accept4() failed (24: Too many open files)

2015/10/27 21:48:36 [alert] 2475#0: *7163915 socket() failed (24: Too many open files) while connecting to upstream...

An article at http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/ provided directions that mostly worked. Below are the steps we followed. The steps that diverged from the article's directions are marked with an *.

  1. * Instead of using su to run ulimit on the nginx account, use ps aux | grep nginx to locate nginx's process IDs. Then query each process's file handle limits using cat /proc/pid/limits (where pid is the process id retrieved from ps). (Note: sudo may be necessary on your system for the cat command here, depending on your system.)
  2. Added fs.file-max = 70000 to /etc/sysctl.conf
@ahoward
ahoward / a.rb
Created May 30, 2014 17:04
this bitchin script can boil virtually any rails project in a pure static ball of goodness suitable for deployment to s3, bitballoon, etc.
#! /usr/bin/env ruby
# this script can create a static build from virtually any rails' project. it
# has two simple requirements.
#
# 1) you have
#
# gem 'passenger'
#
# in your Gemfile
@coreyhaines
coreyhaines / Current shopping cart
Last active December 18, 2015 00:08
Damn you MITPress and your 50% off weekend!
Computing
Paul E. Ceruzzi
ISBN: 9780262517676
Modeling Business Processes
Wil van der Aalst and Christian Stahl
ISBN: 9780262015387
The Reasoned Schemer
Daniel P. Friedman, William E. Byrd, and Oleg Kiselyov
@andrewle
andrewle / leader-election.md
Created April 16, 2012 02:06 — forked from ryandotsmith/process-partitioning.md
Leader Election With Ruby & PostgreSQL

Leader Election With Ruby & PostgreSQL

The Problem

I have a table with millions of rows that needs processing. The type of processing is not really important for this article. We simply need to process some data with Ruby --or any other user-space programming language.

A Solution

module Watchable
def events
@events ||= Hash.new { |h,k| h[k] = [] }
end
def fire event, *args
events[event].each { |e| e[*args] }
end
def on event, &block
@ryandotsmith
ryandotsmith / worker-pattern.md
Created January 23, 2012 05:03
The Worker Pattern

The Worker Pattern

Contents

  • Introduction
  • Definition
  • Examples
  • Links

Introduction