Giter VIP home page Giter VIP 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.

balancers's People

Contributors

d3luxee avatar olivere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

balancers's Issues

Balancer Time_Wait Issue

My team is using the load balancer to horizontally scale and provide processing retention for an application that does cpu intensive calculations on data. The issue we are running into is that it doesn't seem configuring transport attributes on the RoundTripper is not quite opened up for us yet, unless its intended for us to use the http.DefaultTransport. We want to change the MaxIdleConns and MaxIdleConnsPerHost to help avoid time_waits when making requests. Perhaps leaving a parameter open for us when creating the balancer to set our transport will be useful. Just a suggestion really.

Balancer Heartbeat Implementation

Currently it seems that a connection is considered broken if the url provided to the balancer throws an error or returns any status code other than 200. Ideally, I think the case for a valid endpoint would simply just be the connection as, in our case anyway, the root url we provide returns a status of 404 because nothing is provided at our root location. However, it still is considered "up" and/or can receive connections.

Example
http://ourendpoint:80 -> 404
http://ourendpoint:80/path/to/res -> 200

A valid endpoint should be justified in terms of whether or not is connecting or not i think. If we have an issue with our res then that's our problem. Maybe provide an option to remove an endpoint from the balancer if the amount of certain status codes besides 200 exceeds a specified amount? Not sure. I just wanted to open it up for discussion.

Balancer Documentation

There is a lack of documentation on this tool. It would be really helpful to provide usage examples both simple and advanced to help describe usage. Currently the only way to see this is via your test cases.

Memory leak in the RoundRobin balancer

I haven't investigated the details, but the RoundRobin balancer seems to leak memory.

I found out by using it with a service that needed to send big payloads (like, multi megabytes payloads) at recurring intervals. Somehow, removing the RoundRobin and using a randomly built URL solved the problem, so I expected the balancer's logic to be faulty somewhere.

I'll take the time to do a working example of this later to demonstrate the problem.

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.