Coder Social home page Coder Social logo

pooly's Introduction

Pooly Build Status GoDoc

A package inspired by go-hostpool, to manage efficiently pools of connection across multiple hosts. Pooly uses multi-armed bandit algorithms for host selection in order to maximize service connectivity by avoiding faulty hosts.

Currently supported bandit strategies:

  • Softmax
  • Epsilon-greedy
  • Round-robin

Basic Usage

Start two dummy netcat servers.

nc -l -p 1234 &
nc -l -p 12345 &

Get two connections from the "netcat" service using the NetDriver and the RoundRobin strategy (defaults).

package main

import "fmt"
import "github.com/3XX0/pooly"

func ping(s *pooly.Service) error {
	c, err := s.GetConn()
	if err != nil {
		return err
	}
	defer c.Release(&err, pooly.HostUp)

	_, err = c.NetConn().Write([]byte("ping\n"))
	return err
}

func main() {
	s := pooly.NewService("netcat", nil)
	defer s.Close()

	s.Add("127.0.0.1:1234")
	s.Add("127.0.0.1:12345")

	if err := ping(s); err != nil {
		fmt.Println(err)
		return
	}
	if err := ping(s); err != nil {
		fmt.Println(err)
		return
	}
}

Metrics

Pooly exports useful service metrics provided that a statsd server is running and the option ServiceConfig.StatsdAddr is set accordingly.

The following metrics are available:

metric description
hosts.score average score of the service hosts (in percentage)
hosts.count number of hosts registered to the service
conns.count number of connections spawned by the service
conns.fails number of connection failures (temporary included)
conns.put.count number of Release performed
conns.get.count number of GetConn performed
conns.get.delay average delay before receiving a connection from the service (in millisecond)
conns.get.fails number of GetConn failures
conns.active.period average time during which a connection was active (in millisecond)

Example of a grafana dashboard using vizu

Simulations

In order to test the behavior of different strategies, Monte Carlo simulations may be run through the Go testing framework.

go test -tags 'montecarlo_simulation' -v pooly

Softmax strategy sample output

Epsilon-greedy strategy sample output

pooly's People

Contributors

0intro avatar 3xx0 avatar chouquette 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.