https://github.com/pushwoosh/go-connection-pool
Common connection pool for any connections type
https://github.com/pushwoosh/go-connection-pool
connection-pool go golang golang-library
Last synced: 7 months ago
JSON representation
Common connection pool for any connections type
- Host: GitHub
- URL: https://github.com/pushwoosh/go-connection-pool
- Owner: Pushwoosh
- License: wtfpl
- Created: 2019-08-31T14:01:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-16T04:28:05.000Z (over 6 years ago)
- Last Synced: 2025-04-10T18:49:28.179Z (about 1 year ago)
- Topics: connection-pool, go, golang, golang-library
- Language: Go
- Size: 16.6 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# What is it
It's a library with connection pool implementation and all connections in pool work simultaneously.
It's important if you want send more requests than one connection may serve. For example, to send
multiple email- or push-notifications fast.
On other hand it may be useful for site scrapping.
## How to
There are some [examples](./examples/http-get-parallel/main.go) and here [too](./pkg/pool/implementation_test.go).
So to start you need implement your own:
- [connection](./pkg/connection/interfaces.go)
- [dialer](./pkg/connection/interfaces.go)
- [message](./pkg/message/interfaces.go)
and you are ready to download all internet:
```go
go func() {
_ = p.Serve(inChan, outChan)
close(outChan)
}()
```
### Benchmarks
It's too hard to make simple benchmarks, because project aims to
improve performance in `IO`-bound tasks so, there are some metrics
from my mac:
```bash
$ time go run examples/http-get-sequential/main.go -req-num=100
...
2019/08/31 21:04:58 Completed
real 0m6.245s
user 0m0.768s
sys 0m0.556s
```
```bash
$ time go run examples/http-get-parallel/main.go -conn-num=10 -req-num=100
...
2019/08/31 21:10:37 Completed
real 0m1.232s
user 0m0.762s
sys 0m0.469s
```
So in example on localhost pool wins in ~5 times.
But if we try to use as target, for example, google.com, than the difference will be greater:
```bash
time go run examples/http-get-sequential/main.go -req-num=100 -url="https://google.com"
...
2019/08/31 21:48:32 Completed
real 0m58.127s
user 0m1.064s
sys 0m0.653s
```
```bash
time go run examples/http-get-parallel/main.go -conn-num=20 -req-num=100 -url="https://google.com"
...
2019/08/31 21:46:39 Completed
real 0m5.300s
user 0m1.808s
sys 0m0.610s
```
The difference is obvious.