Giter VIP home page Giter VIP logo

lagoon's Introduction

Lagoon

Golang net.Conn Connection Pool

GoDoc

This package was inspired by github.com/fatih/pool - This is NOT a fork, it will function differently!!!

The main differences are:

  • The connection pool is capped and Dial will block once the pool is full!
  • Connections are capped with a Buffer that can be optionally shared between pools.
  • Dial can Timeout if we fail to acquire a spot from the Buffer queue! (DialTimeout or similar should be used within the Dial function)
  • DialInitial can not garauntee that we will always dial the initial amount due to the possibility of a shared Buffer.

Install

go get -t -u sabey.co/lagoon

Usage

// create a shared buffer
buffer := CreateBuffer(10, time.Second*2)

// create a config for our lagoon instance
config := &Config{
	Dial: func() (net.Conn, error) {
		return net.DialTimeout("tcp", "service.local:25", time.Second*30)
	},
	DialInitial: 5,
	Buffer:      buffer,
}

// create a lagoon instance
l, err := CreateLagoon(config)

// dial
c, err := l.Dial()

// return connection back to the pool
c.Close()

// dial
c, err := l.Dial()

// remove connection from the pool on close
c.(*Connection).Disable()

// close connection
c.Close()

lagoon's People

Contributors

sabey avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

jangocheng

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.