https://github.com/b1nary-gr0up/violin
VIOLIN worker/connection pool
https://github.com/b1nary-gr0up/violin
connection-pool go worker-pool
Last synced: 7 months ago
JSON representation
VIOLIN worker/connection pool
- Host: GitHub
- URL: https://github.com/b1nary-gr0up/violin
- Owner: B1NARY-GR0UP
- License: apache-2.0
- Created: 2023-06-04T09:17:48.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-13T05:17:34.000Z (almost 2 years ago)
- Last Synced: 2025-03-24T03:23:34.303Z (about 1 year ago)
- Topics: connection-pool, go, worker-pool
- Language: Go
- Homepage:
- Size: 104 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

VIOLIN worker pool / connection pool, rich APIs and configuration options are provided.
[](https://goreportcard.com/report/github.com/B1NARY-GR0UP/violin)
## Install
```shell
go get github.com/B1NARY-GR0UP/violin
```
## Quick Start
### Worker Pool
```go
package main
import (
"fmt"
"github.com/B1NARY-GR0UP/violin"
)
func main() {
v := violin.New()
defer v.Shutdown()
v.Submit(func() {
fmt.Println("Hello, VIOLIN!")
})
}
```
### Connection Pool
```go
package main
import (
"net"
"time"
"github.com/B1NARY-GR0UP/violin/cool"
)
func main() {
producer := func() (net.Conn, error) {
return net.Dial("your-network", "your-address")
}
c, _ := cool.New(5, 30, producer, cool.WithConnIdleTimeout(30*time.Second))
defer c.Close()
_ = c.Len()
conn, _ := c.Get()
_ = conn.Close()
if cc, ok := conn.(*cool.Conn); ok {
cc.MarkUnusable()
if cc.IsUnusable() {
_ = cc.Close()
}
}
}
```
## Configuration
### Worker Pool
| Option | Default | Description |
|-------------------------|-------------------|-------------------------------------------|
| `WithMinWorkers` | `0` | Set the minimum number of workers |
| `WithMaxWorkers` | `5` | Set the maximum number of workers |
| `WithWorkerIdleTimeout` | `3 * time.Second` | Set the destroyed timeout of idle workers |
### Connection Pool
| Option | Default | Description |
|-----------------------|---------|---------------------------------|
| `WithConnIdleTimeout` | `0` | Set the connection idle timeout |
## Blogs
- [GO: How to Write a Worker Pool](https://dev.to/justlorain/go-how-to-write-a-worker-pool-1h3b) | [中文](https://juejin.cn/post/7244733519948333111)
## Credits
Sincere appreciation to the following repositories that made the development of VIOLIN possible.
- [gammazero/workerpool](https://github.com/gammazero/workerpool)
- [fatih/pool](https://github.com/fatih/pool)
## License
VIOLIN is distributed under the [Apache License 2.0](./LICENSE). The licenses of third party dependencies of VIOLIN are explained [here](./licenses).
## ECOLOGY
VIOLIN is a Subproject of the Basic Middleware Service