{"id":16316785,"url":"https://github.com/makasim/backpressure","last_synced_at":"2025-05-13T15:30:49.106Z","repository":{"id":64887040,"uuid":"576913463","full_name":"makasim/backpressure","owner":"makasim","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-26T15:48:56.000Z","size":56,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-16T19:48:22.592Z","etag":null,"topics":["aimd","backpressure","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/makasim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-11T11:59:42.000Z","updated_at":"2024-10-09T05:23:17.000Z","dependencies_parsed_at":"2023-01-31T00:31:03.477Z","dependency_job_id":null,"html_url":"https://github.com/makasim/backpressure","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makasim%2Fbackpressure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makasim%2Fbackpressure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makasim%2Fbackpressure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makasim%2Fbackpressure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makasim","download_url":"https://codeload.github.com/makasim/backpressure/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253970156,"owners_count":21992433,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aimd","backpressure","golang"],"created_at":"2024-10-10T22:05:37.142Z","updated_at":"2025-05-13T15:30:49.074Z","avatar_url":"https://github.com/makasim.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backpressure\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/makasim/backpressure\"\n)\n\nfunc main() {\n\tbp, _ := backpressure.NewAIMD(backpressure.AIMDConfig{\n\t\tDecideInterval:  time.Second,\n\t\tIncreasePercent: 0.02,\n\t\tDecreasePercent: 0.2,\n\t})\n\n\tc := \u0026http.Client{}\n\n\twg := sync.WaitGroup{}\n\n\t// later, while sending request to origin server\n\n\tfor i := 0; i \u003c 100; i++ {\n\t\twg.Add(1)\n\t\tgo func() {\n\t\t\tdefer wg.Done()\n\t\t\tt, allowed := bp.Acquire()\n\t\t\tif !allowed {\n\t\t\t\tlog.Println(\"backpressure activated\")\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\treq, _ := http.NewRequest(\"GET\", \"https://example.com\", http.NoBody)\n\n\t\t\tresp, err := c.Do(req)\n\t\t\tt.Congested = backpressure.IsResponseCongested(resp, err)\n\t\t\tbp.Release(t)\n\t\t}()\n\t}\n\n\twg.Done()\n}\n```\n\n\n## Benchmark\n\n```shell\n$go test -run=XXX -v -bench=.\ngoos: darwin\ngoarch: arm64\npkg: github.com/makasim/backpressure\nBenchmarkAIMD_OK\nBenchmarkAIMD_OK-10           \t15986818\t        66.95 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkAIMD_Congested\nBenchmarkAIMD_Congested-10    \t18400120\t        65.22 ns/op\t       0 B/op\t       0 allocs/op\nPASS\nok  \tgithub.com/makasim/backpressure\t2.758s\n```\n\n## References \n\n* https://www.youtube.com/watch?v=m64SWl9bfvk\n* https://en.wikipedia.org/wiki/TCP_congestion_control\n* https://www.youtube.com/watch?v=UdT0xVacEUg\n* https://github.com/marselester/capacity\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakasim%2Fbackpressure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakasim%2Fbackpressure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakasim%2Fbackpressure/lists"}