Giter VIP home page Giter VIP logo

pool's Introduction

Pool

GoDoc Go Report Card Build Status Travis Build Status Semaphore Sourcegraph Open Source Helpers LICENSE GitHub code size in bytes Release LICENSE

Pool is Used to manage and reuse client connections to service cluster.

Pool provides several key features:

  • General Purpose - Pool for GRPC,RPC,TCP.support RPC timeout.

  • Support Cluster - Connet to Cluster.

  • Danamic Update - Danamic update targets.

Pool runs on Linux, Mac OS X, and Windows.

Note: Random to pick a target to get one connection for loadbalance.

Install

go get -u gopkg.in/flyaways/pool.v1

Usage

import "gopkg.in/flyaways/pool.v1"

Example

package main

import (
	"log"
	"time"

	"gopkg.in/flyaways/pool.v1"
	"google.golang.org/grpc"
)

func main() {
	options := &pool.Options{
		InitTargets:  []string{"127.0.0.1:8080"},
		InitCap:      5,
		MaxCap:       30,
		DialTimeout:  time.Second * 5,
		IdleTimeout:  time.Second * 60,
		ReadTimeout:  time.Second * 5,
		WriteTimeout: time.Second * 5,
	}

	
	p, err := pool.NewGRPCPool(options, grpc.WithInsecure() //for grpc
	//p, err := pool.NewRPCPool(options) 			//for rpc
	//p, err := pool.NewTCPPool(options)			//for tcp

	if err != nil {
		log.Printf("%#v\n", err)
		return
	}

	if p == nil {
		log.Printf("p= %#v\n", p)
		return
	}

	defer p.Close()

	//todo
	//danamic update targets
	//options.Input()<-&[]string{}

	conn, err := p.Get()
	if err != nil {
		log.Printf("%#v\n", err)
		return
	}

	defer p.Put(conn)

	//todo
	//conn.DoSomething()

	log.Printf("len=%d\n", p.IdleCount())
}

Reference

Contribution Welcomed !

Contributors

License

  • The MIT License (MIT) - see LICENSE for more details

FOSSA Status

pool's People

Contributors

flyaways 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.