GithubHelp home page GithubHelp logo

balancers's Introduction

Balancers

Balancers provides implementations of HTTP load-balancers.

Build Status Godoc license

What does it do?

Balancers gives you a http.Client from net/http that rewrites your requests' scheme, host, and userinfo according to the rules of a balancer. A balancer is simply an algorithm to pick the host for the next request a http.Client.

How does it work?

Suppose you have a cluster of two servers (on two different URLs) and you want to load balance between them. A very simple implementation can be done with the round-robin scheduling algorithm. Round-robin iterates through the list of available hosts and restarts at the first when the end is reached. Here's some code that illustrates that:

// Get a balancer that performs round-robin scheduling between two servers.
balancer, err := roundrobin.NewBalancerFromURL("https://server1.com", "https://server2.com")

// Get a HTTP client based on that balancer.
client := balancers.NewClient(balancer)

// Now request some data. The scheme, host, and user info will be rewritten
// by the balancer; you'll never get data from http://example.com, only data
// from http://server1.com or http://server2.com.
client.Get("http://example.com/path1?foo=bar") // rewritten to https://server1.com/path1?foo=bar
client.Get("http://example.com/path1?foo=bar") // rewritten to https://server2.com/path1?foo=bar
client.Get("http://example.com/path1?foo=bar") // rewritten to https://server1.com/path1?foo=bar
client.Get("/path1?foo=bar")                   // rewritten to https://server2.com/path1?foo=bar

Status

The current state of Balancers is a proof-of-concept. It didn't touch production systems yet.

Credits

Thanks a lot for the great folks working on Go.

LICENSE

MIT-LICENSE. See LICENSE or the LICENSE file provided in the repository for details.

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.