Skip to content
forked from 3XX0/pooly

connection pool library based on multi-armed bandit algorithms

Notifications You must be signed in to change notification settings

bennyscetbun/pooly

 
 

Repository files navigation

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 (Round-robin is the strategy used by default).

package main

import "github.com/3XX0/pooly"

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

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

	c, err := s.GetConn()
	if err != nil {
		println("could not get connection")
		return
	}

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

	if err := c.Release(err, pooly.HostUp); err != nil {
		println("could not release connection")
		return
	}

	c, err = s.GetConn()
	if err != nil {
		println("could not get connection")
		return
	}

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

	if err := c.Release(err, pooly.HostUp); err != nil {
		println("could not release connection")
		return
	}
}

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

About

connection pool library based on multi-armed bandit algorithms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%