https://github.com/samber/go-tcp-pool
✨ Drop-in replacement to net.Conn with pooling and auto-reconnect
https://github.com/samber/go-tcp-pool
bandwidth connection go parallel pool pooling pressure reconnect retry round-robin tcp
Last synced: 6 months ago
JSON representation
✨ Drop-in replacement to net.Conn with pooling and auto-reconnect
- Host: GitHub
- URL: https://github.com/samber/go-tcp-pool
- Owner: samber
- License: mit
- Created: 2023-07-23T22:43:41.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-09T18:03:32.000Z (11 months ago)
- Last Synced: 2024-11-09T19:17:48.642Z (11 months ago)
- Topics: bandwidth, connection, go, parallel, pool, pooling, pressure, reconnect, retry, round-robin, tcp
- Language: Go
- Homepage: https://pkg.go.dev/github.com/samber/go-tcp-pool
- Size: 25.4 KB
- Stars: 15
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# TCP pooling
[](https://github.com/samber/go-tcp-pool/releases)

[](https://pkg.go.dev/github.com/samber/go-tcp-pool)

[](https://goreportcard.com/report/github.com/samber/go-tcp-pool)
[](https://codecov.io/gh/samber/go-tcp-pool)
[](https://github.com/samber/go-tcp-pool/graphs/contributors)
[](./LICENSE)✨ Drop-in replacement to `net.Conn` with pooling and auto-reconnect.
## 🚀 Install
```sh
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](https://pkg.go.dev/github.com/samber/go-tcp-pool)
### Create a TCP connection pool
```sh
# Start a tcp server
ncat -l 9999 -k
``````go
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
- [x] Implement round-robin connection pool
- [x] Implement auto-reconnect
- [ ] Implement Read()
- [ ] Implement other load-balancing strategies
- Max idle time
- MinConn + MaxConn## 🤝 Contributing
- Ping me on Twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))
- Fork the [project](https://github.com/samber/go-tcp-pool)
- Fix [open issues](https://github.com/samber/go-tcp-pool/issues) or request new featuresDon't hesitate ;)
```bash
# Install some dev dependencies
make tools# Run tests
make test
# or
make watch-test
```## 👤 Contributors

## 💫 Show your support
Give a ⭐️ if this project helped you!
[](https://github.com/sponsors/samber)
## 📝 License
Copyright © 2023 [Samuel Berthe](https://github.com/samber).
This project is [MIT](./LICENSE) licensed.