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
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
}
}
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