Skip to content

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

License

Notifications You must be signed in to change notification settings

samber/go-tcp-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.