Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/makasim/backpressure
https://github.com/makasim/backpressure
aimd backpressure golang
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/makasim/backpressure
- Owner: makasim
- Created: 2022-12-11T11:59:42.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-26T15:48:56.000Z (about 2 years ago)
- Last Synced: 2024-11-06T10:53:12.926Z (about 2 months ago)
- Topics: aimd, backpressure, golang
- Language: Go
- Homepage:
- Size: 54.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Backpressure
```go
package mainimport (
"log"
"net/http"
"sync"
"time""github.com/makasim/backpressure"
)func main() {
bp, _ := backpressure.NewAIMD(backpressure.AIMDConfig{
DecideInterval: time.Second,
IncreasePercent: 0.02,
DecreasePercent: 0.2,
})c := &http.Client{}
wg := sync.WaitGroup{}
// later, while sending request to origin server
for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
defer wg.Done()
t, allowed := bp.Acquire()
if !allowed {
log.Println("backpressure activated")
return
}req, _ := http.NewRequest("GET", "https://example.com", http.NoBody)
resp, err := c.Do(req)
t.Congested = backpressure.IsResponseCongested(resp, err)
bp.Release(t)
}()
}wg.Done()
}
```## Benchmark
```shell
$go test -run=XXX -v -bench=.
goos: darwin
goarch: arm64
pkg: github.com/makasim/backpressure
BenchmarkAIMD_OK
BenchmarkAIMD_OK-10 15986818 66.95 ns/op 0 B/op 0 allocs/op
BenchmarkAIMD_Congested
BenchmarkAIMD_Congested-10 18400120 65.22 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/makasim/backpressure 2.758s
```## References
* https://www.youtube.com/watch?v=m64SWl9bfvk
* https://en.wikipedia.org/wiki/TCP_congestion_control
* https://www.youtube.com/watch?v=UdT0xVacEUg
* https://github.com/marselester/capacity