Git Product home page Git Product logo

aimdcloser's Introduction

aimdcloser

Build Status GoDoc Coverage Status

aimdcloser is a closer implementation for github.com/cep21/circuit. It is a closer that increases how many requests it allows in an opened circuit according to Additive increase/multiplicative decrease algorithm. The circuit closes when for a configured duration:

  • No requests have failed
  • No requests have been not allowed (additive increase is high enough for the rate)

Usage

Have your manager use a ratecloser.CloserFactory and your circuits will be created of this type.

    func ExampleCloserFactory() {
        // Tell your circuit manager to use the rate limited closer
        m := circuit.Manager{
            DefaultCircuitProperties: []circuit.CommandPropertiesConstructor{
                func(_ string) circuit.Config {
                    return circuit.Config{
                        General: circuit.GeneralConfig{
                            OpenToClosedFactory:CloserFactory(CloserConfig{
                                CloseOnHappyDuration: time.Second * 10,
                            }),
                        },
                    }
                },
            },
        }
        // Make circuit from manager
        c := m.MustCreateCircuit("example_circuit")
        // The closer should be a closer of this type
        _ = c.OpenToClose.(*Closer)
        // Output:
    }

Benchmarks

Run on my mac.

    < go test -bench .
    goos: darwin
    goarch: amd64
    pkg: github.com/cep21/aimdcloser/ratecloser
    BenchmarkCloser_Allow_10-16                	10000000	       155 ns/op	       0 B/op	       0 allocs/op
    BenchmarkCloser_AllowSuccess_10-16         	 5000000	       392 ns/op	       0 B/op	       0 allocs/op
    BenchmarkCloser_AllowSuccessClose_10-16    	 3000000	       480 ns/op	       0 B/op	       0 allocs/op
    BenchmarkCloser_AllowFailureClose_10-16    	 3000000	       513 ns/op	       0 B/op	       0 allocs/op
    PASS
    ok  	github.com/cep21/aimdcloser/ratecloser	8.108s

aimdcloser's People

Contributors

cep21 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.