• Stars
    star
    310
  • Rank 134,926 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 14 years ago
  • Updated about 13 years ago

Reviews

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

Repository Details

Keep track of service error rates using redis. Degrade functionality if they're too high.

degrade¶ ↑

Keep track of error rates using redis. Degrade functionality if they’re too high.

Install it¶ ↑

gem install degrade

How it works¶ ↑

Setup one instance per feature.

$redis             = Redis.new
$rollout           = Rollout.new($redis) # see http://github.com/jamesgolick/rollout
$degrade_cassandra = Degrade.new(@redis, :name             => :cassandra,
                                         :sample           => 5000,            # optional - 5000 is the default
                                         :minimum          => 100,             # optional - 100 is the default
                                         :threshold        => 0.1,             # optional - 0.1 is the default
                                         :errors           => [StandardError], # optional - [StandardError] is the default
                                         :failure_strategy => lambda { $rollout.deactivate_all(:cassandra) }

There are a bunch of options here:

* name: The name of the feature.
* sample: We zero the counters every n requests. Define n here.
* minimum: What's the minimum number of requests we need to see before we decide that the threshold has been met? Without this, if the first request of a given sample is a failure, we'd be failing the service.
* threshold: Percentage of failure requests necessary to trigger a failure.
* errors: Which errors should cause us to mark a failures?
* failure_strategy: The proc that will get called when the threshold is met. See http://github.com/jamesgolick/rollout if you don't have an existing system for disabling features on the fly.

The only thing left to do is wrap calls to whatever it is that might fail in a call to perform():

$degrade_cassandra.perform { $cassandra.get("Timelines", "1/everything") }

Note that degrade doesn’t actually handle the degradation for you. You still have to wrap sections of functionality with whatever mechanism you use to disable features (i.e. rollout).

Driver decorators¶ ↑

Wrapping every call to a service in $degrade.perform() is a hassle and will require a lot of changes to your code. You’re better off decorating your driver.

Let’s say we had a service called NewsService:

class NewsService < SomeRPCMechanism
  def get_news(*args)
    # ...
  end
end

We’d decorate it like this:

class NewsServiceWithDegradation
  def initialize(news_service, degrade)
    @news_service = news_service
    @degrade      = degrade
  end

  def get_news(*args)
    @degrade.perform { @news_service.get_news(*args) }
  end
end

We’re doing this for one of our services and it’s working pretty well.

Known issues / concerns¶ ↑

Making a bunch of requests to services whose drivers are wrapped in this could cause problems if your services / site are extremely high throughput. This could be improved somewhat by adding some randomness to threshold checking and sample resetting so that those things aren’t checked every request. The service we’re currently using this with runs at about 250 req / s which is a long way before any problems are likely.

Also, obviously calls to redis add latency to your requests. Make sure you’re okay with this.

Don’t try to use this on redis itself. If you do, the universe will enter a state of infinite recursion.

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 James Golick. See LICENSE for details.

More Repositories

1

resource_controller

Rails RESTful controller abstraction plugin.
Ruby
498
star
2

timeline_fu

Ruby
410
star
3

active_presenter

The presenter library you already know.
Ruby
302
star
4

is_taggable

Tagging that doesn't want to be on steroids. It's skinny and happy to stay that way
Ruby
213
star
5

trample

A Better Load Simulator
Ruby
160
star
6

observational

Use the observer pattern to better divide your objects' responsibilities.
Ruby
116
star
7

attribute_fu

a better version of this functionality is in rails 2.3. use that!
Ruby
99
star
8

always_verify_ssl_certificates

Ruby's net/http is setup to never verify SSL certificates by default. Most ruby libraries do the same. That means that you're not verifying the identity of the server you're communicating with and are therefore exposed to man in the middle attacks. This gem monkey-patches net/http to force certificate verification and make turning it off impossible.
Ruby
97
star
9

blank

Blank is GiraffeSoft’s blank rails starter app.
Ruby
61
star
10

zebra

One line tests without the smells.
Ruby
56
star
11

enum_field

Ruby
55
star
12

statsd.scala

statsd on the jvm
Scala
48
star
13

conductor

Build clusters in the cloud with conductor.
Ruby
48
star
14

munin_plugin

Ruby
46
star
15

scala-resque-worker

Scala
44
star
16

action_messager

Dead simple IM notifications for your app
Ruby
43
star
17

cassandra-munin-plugins

Munin plugins for apache cassandra.
42
star
18

classy_resources

Think resource_controller, except for sinatra.
Ruby
41
star
19

lexical_uuid

UUIDs that are byte-ordered lamport clocks (timestamp, worker_id). Much simpler than type-1 UUID's crappy, weirdo layout.
Ruby
31
star
20

markaby

Markaby patched to run on rails 2.0.2
Ruby
23
star
21

tweet

Tweet from the command line.
Ruby
22
star
22

timeline_fu-example

Ruby
22
star
23

fetlife-nagios-plugins

Nagios plugins in use at FetLife. Services include: resque, cassandra, etc.
Ruby
22
star
24

lexical_uuid.erl

UUIDs that are byte-ordered lamport clocks (timestamp, worker_id). Much simpler than type-1 UUID's crappy, weirdo layout.
Erlang
21
star
25

openvpn-recipes

Get OpenVPN up and running on Ubuntu, using Chef. Great way to beat geofencing!
Ruby
19
star
26

dotfiles

Vim Script
17
star
27

friendly

http://jamesgolick.com/2009/12/16/introducing-friendly-nosql-with-mysql-in-ruby.html
Ruby
17
star
28

has_browser

has_browser makes it possible to create simple, parameterized browser interfaces to your models. That is, given a set of parameters, return all the models that match.
Ruby
16
star
29

conductor-rails

A rails stack for conductor.
Ruby
12
star
30

scrawny

a lightweight, RESTful persistent queue on top of thin, rack and invisible in < 60 LoC
Ruby
11
star
31

expectations

expectations is a lightweight unit testing framework.
Ruby
11
star
32

starling-on-invisible

Proof of concept that you can build a queueing server and client RESTfully, leveraging starling's persistent queue code, a lightweight web framework, and thin.
Ruby
10
star
33

scala-connection-pool

Connection pool abstractions in scala. Supports load balancing and failover in a thread-safe manner. Defers to commons-pool for the actual pooling.
Scala
9
star
34

spymemcached-gem

A jruby-only memcached client and rails cache store that uses spymemcached under the hood.
Ruby
7
star
35

action_mailer_verp

Send VERP emails with actionmailer. http://en.wikipedia.org/wiki/Variable_envelope_return_path
Ruby
7
star
36

dirty_callbacks

Ruby
6
star
37

per_mailer_smtp_settings

Setup different smtp settings per ActionMailer::Base subclass.
Ruby
6
star
38

memcache-lock

Extraction of the lock from cache-money.
Ruby
6
star
39

what_does_this_error_mean-rails

Rails plugin for integration with whatdoesthiserrormean.com
Ruby
6
star
40

file-sherpa

Upload progress bars for jQuery.
JavaScript
5
star
41

rollout_rest_api

A sinatra app that exposes a REST API for rollout.
Ruby
5
star
42

zfs-mysql-backup

4
star
43

fetlife-packages

Binary FreeBSD packages in use at fetlife.com (NSFW).
4
star
44

what_does_this_error_mean-merb

Ruby
3
star
45

sbt-ruby

sbt plugin for including ruby code and rubygems in the build.
Scala
3
star
46

smemcache

A scala wrapper around spymemcached.
Scala
3
star
47

rest_client-cocoa

Ruby
2
star
48

vim_conf

2
star
49

restful_roles

Ruby
2
star
50

rubyee-freebsd-port

Adapted from the ruby18 port. I'm new to freebsd and ports, so it's probably all wrong!
2
star
51

jgmalloc

C
2
star
52

health

Health checks for rails.
Ruby
2
star
53

activerecordless_migrations

Ruby
2
star
54

memcached.erl

because obviously I wanted to write a fucking memcached client
Erlang
2
star
55

gperftools

C++
2
star
56

r_c-2.1.1

2
star
57

tempo_cli

CLI for sending commands to tempo app.
Ruby
2
star
58

markdownj-gem

(J)Ruby wrapper around markdownj.
Ruby
1
star
59

telephos

A really simple Scala wrapper around Cassandra's thrift bindings. No DSLs here.
Scala
1
star
60

jruby-scala-issue

Ruby
1
star
61

client_proxy

Basic ruby proxy class to use around service clients that handles retrying requests and failover.
Ruby
1
star
62

thrift-exception-notifier

If you run thrift services in production, it's handy to receive an email when shit breaks.
Scala
1
star
63

uriparser

C
1
star
64

rpmspecs

RPM specs that I'm maintaining. I'm not good at this. They're probably all wrong.
1
star