GithubHelp home page GithubHelp logo

samber / go-tcp-pool Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 0.0 10 KB

✨ Drop-in replacement to net.Conn with pooling and auto-reconnect

Home Page: https://pkg.go.dev/github.com/samber/go-tcp-pool

License: MIT License

Makefile 15.99% Go 84.01%
bandwidth connection go parallel pool pooling pressure reconnect retry round-robin

go-tcp-pool's Introduction

TCP pooling

tag Go Version GoDoc Build Status Go report Coverage Contributors License

✨ Drop-in replacement to net.Conn with pooling and auto-reconnect.

🚀 Install

go get github.com/samber/go-tcp-pool

This library is v1 and follows SemVer strictly. No breaking changes will be made to exported APIs before v2.0.0.

💡 Usage

GoDoc: https://pkg.go.dev/github.com/samber/go-tcp-pool

Create a TCP connection pool

# Start a tcp server
ncat -l 9999 -k
import pool "github.com/samber/go-tcp-pool"

conn, err := pool.Dial("tcp", "localhost:9999")
if err != nil {
    log.Fatal(err)
}

conn.SetPoolSize(10)
conn.SetMaxRetries(10)
conn.SetRetryInterval(10 * time.Millisecond)

// a tcp connection will be used in a round-robin manner
n, err := conn.Write([]byte("Hello, world!\n"))
if err != nil {
    log.Fatal(err)
}

// will always return an error
conn.Read(...)

🚀 @TODO

  • Implement round-robin connection pool
  • Implement auto-reconnect
  • Implement Read()
  • Implement other load-balancing strategies
    • Max idle time
    • MinConn + MaxConn

🤝 Contributing

Don't hesitate ;)

# Install some dev dependencies
make tools

# Run tests
make test
# or
make watch-test

👤 Contributors

Contributors

💫 Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

📝 License

Copyright © 2023 Samuel Berthe.

This project is MIT licensed.

go-tcp-pool's People

Contributors

samber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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