• Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 12 months ago

Reviews

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

Repository Details

๐Ÿ”Œ circuit breaker based on netflix/hystrix but in ruby, hopefully commands/semaphores eventually too

Resilient

Some tools to aid in resiliency in Ruby. For now, just a circuit breaker (stolen from based on hystrix). Soon much more...

Nothing asynchronous or thread safe yet either, but open to it and would like to see more around it in the future. See more here: jnunemaker/resilient#18.

Installation

Add this line to your application's Gemfile:

gem "resilient"

And then execute:

$ bundle

Or install it yourself as:

$ gem install resilient

Usage

require "resilient/circuit_breaker"

# default properties for circuit, CircuitBreaker.get is used instead of
# CircuitBreaker.new as `get` keeps a registry of circuits by key to prevent
# creating multiple instances of the same circuit breaker for a key; not using
# `get` means you would have multiple instances of the circuit breaker and thus
# separate state and metrics; you can read more in examples/get_vs_new.rb
circuit_breaker = Resilient::CircuitBreaker.get("example")
if circuit_breaker.allow_request?
  begin
    # do something expensive
    circuit_breaker.success
  rescue => boom
    circuit_breaker.failure
    # do fallback
  end
else
  # do fallback
end

customize properties of circuit:

circuit_breaker = Resilient::CircuitBreaker.get("example", {
  # at what percentage of errors should we open the circuit
  error_threshold_percentage: 50,
  # do not try request again for 5 seconds
  sleep_window_seconds: 5,
  # do not open circuit until at least 5 requests have happened
  request_volume_threshold: 5,
})
# etc etc etc

force the circuit to be always open:

circuit_breaker = Resilient::CircuitBreaker.get("example", force_open: true)
# etc etc etc

force the circuit to be always closed (great way to test in production with no impact, all instrumentation still runs which means you can measure in production with config and gain confidence while never actually opening a circuit incorrectly):

circuit_breaker = Resilient::CircuitBreaker.get("example", force_closed: true)
# etc etc etc

customize rolling window to be 10 buckets of 1 second each (10 seconds in all):

circuit_breaker = Resilient::CircuitBreaker.get("example", {
  window_size_in_seconds: 10,
  bucket_size_in_seconds: 1,
})
# etc etc etc

Default Properties

Property Default Notes
:force_open false allows forcing the circuit open (stopping all requests)
:force_closed false allows ignoring errors and therefore never trip "open" (e.g. allow all traffic through); normal instrumentation will still happen, thus allowing you to "test" configuration live without impact
:instrumenter Instrumenters::Noop what to use to instrument all events that happen (e.g. ActiveSupport::Notifications)
:sleep_window_seconds 5 seconds after tripping circuit before allowing retry
:request_volume_threshold 20 number of requests that must be made within a statistical window before open/close decisions are made using stats
:error_threshold_percentage 50 % of "marks" that must be failed to trip the circuit
:window_size_in_seconds 60 number of seconds in the statistical window
:bucket_size_in_seconds 10 size of buckets in statistical window
:metrics Resilient::Metrics.new metrics instance used to keep track of success and failure

Tests

To ensure that you have clean circuit breakers for each test case, be sure to run the following in the setup for your tests (which resets the default registry and thus clears all the registered circuits) either before every test case or at a minimum each test case that uses circuit breakers.

Resilient::CircuitBreaker::Registry.reset

Note: If you use a non-default registry, you'll need to reset that on your own. If you don't know what I'm talking about, you are fine.

Development

# install dependencies
script/bootstrap

# run tests
script/test

# ...or to auto run tests with guard
script/watch

# to get a shell to play in
script/console

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jnunemaker/resilient.

License

The gem is available as open source under the terms of the MIT License.

Release (for maintainers)

  • increment version based on semver
  • git commit version change
  • script/release (releases to rubygems and git tags)

More Repositories

1

httparty

๐ŸŽ‰ Makes http fun again!
Ruby
5,789
star
2

flipper

๐Ÿฌ Beautiful, performant feature flags for Ruby.
Ruby
3,295
star
3

crack

Really simple JSON and XML parsing, ripped from Merb and Rails.
Ruby
539
star
4

nunes

๐Ÿ“ˆ The friendly gem that instruments everything for you, like I would if I could.
Ruby
498
star
5

fancy-zoom

[DEAD] Zoomy JavaScript based loosely on Fancy Zoom by Cabel Sasser.
JavaScript
475
star
6

canable

Simple Ruby authorization system.
Ruby
312
star
7

happymapper

[unmaintained] XML to object mapping library
Ruby
300
star
8

twitter-app

example rails 3 application that uses oauth
Ruby
132
star
9

joint

[DEAD AND UNMAINTAINED] MongoMapper and GridFS joined in file upload love.
Ruby
129
star
10

user_stamp

A Rails plugin that adds the ability to automatically stamp each record with the currently logged in user.
Ruby
84
star
11

flipper-ui

[MOVED] ... to main flipper repo. See readme.
67
star
12

google-weather

stupid simple fetching of the weather using google's api
Ruby
54
star
13

bin

DEAD AND UNMAINTAINED. ActiveSupport MongoDB Cache store.
Ruby
54
star
14

scrobbler

[DEAD] Scrobbler is a wrapper for the audioscrobbler (last.fm) web services.
Ruby
48
star
15

hunt

really simple search for mongomapper
Ruby
38
star
16

lorem

Ever get tired of opening up lipsum.com, filling out a form and waiting for it to give you your filler text? Yeah, me too. I threw this together in an hour to generate lipsum text from the command line.
Ruby
33
star
17

scam

Really basic fake model for doing types in memory
Ruby
32
star
18

dotfiles

Some of my dotfiles, nothing fancy or worthwhile
Shell
30
star
19

googlereader

[DEAD AND UNMAINTAINED] Wrapper for Google Reader's undocumented and possibly "unstable" API. By unstable, I mean if they haven't documented it, then they could change it at anytime without notice.
Ruby
28
star
20

cassanity

Brings sanity to CQL + Ruby.
Ruby
25
star
21

columbus

Autodiscovers feeds from urls
Ruby
24
star
22

gemwhois

Whois for gems, because gem names are like domains in the 90's
Ruby
23
star
23

googlebase

[DEAD] Google Base Auth Class is a base for authenticating to google and making requests to google services.
Ruby
21
star
24

brow

๐Ÿคจ A generic background thread worker for shipping events to some API backend.
Ruby
20
star
25

wand

Mime-Type gem with fallback to unix file command. You most likely don't need this gem.
Ruby
20
star
26

javascripts

[DEAD] some various js files and examples for me to refer to and use
JavaScript
17
star
27

stars

collects github.com stars from people you follow
Ruby
14
star
28

adapter-mongo

Adapter for mongo
Ruby
13
star
29

adapter-redis

Redis adapter
Ruby
12
star
30

flipper-redis

[MOVED] into flipper, check out readme for more
11
star
31

mirrored

[DEAD] Mirrored is a wrapper for the mirrored del.icio.us and ma.gnolia apis.
Ruby
11
star
32

ag

Nothing serious or finished, just playing with events, feeds, activities, timelines, wooooooooooo
Ruby
10
star
33

adapter-riak

Riak adapter
Ruby
9
star
34

wufoo

simple wrapper for the wufoo submission api
Ruby
9
star
35

wordpress_live_search_plugin

[DEAD] live search plugin for wordpress that just works (with prototype)
PHP
8
star
36

twitter

The twitter gem has moved to https://github.com/sferik/twitter
7
star
37

common_helpers

[old and dead] helpers that i use often in apps, nothing special
Ruby
6
star
38

crdts

Nothing serious or finished, just playing with convergent replicated data types
Ruby
6
star
39

adapter-memcached

Memcached adapter
Ruby
6
star
40

snitch

[DEAD AND UNMAINTAINED] Drop dead easy subversion commit notifications.
Ruby
5
star
41

chinwag

[DEAD] chat app that steve and i are playing with, uses google app engine, html5, css3 and jquery
Python
5
star
42

toystore-mongo

Mongo integration for Toystore
Ruby
5
star
43

tao

Nothing serious or finished, just playing with facebook tao concepts
Ruby
5
star
44

scout-plugins

scout plugins as i make them...
Ruby
4
star
45

flipper-mongo

[MOVED] merged into flipper repo, check out readme for more
3
star
46

disk_queue

Nothing to see here. Move along.
Ruby
3
star
47

adapter-cassanity

Adapter for Cassanity
Ruby
1
star
48

clostar

star slurper
Clojure
1
star
49

jnunemaker.github.com

my new blog
CSS
1
star
50

prey

[UNFINISHED] Kestrel client gem based on thrift interface.
Ruby
1
star
51

flipper-cassanity

Cassanity adapter for Flipper.
Ruby
1
star