{"id":13793983,"url":"https://github.com/aviddiviner/gin-limit","last_synced_at":"2026-01-12T02:57:46.697Z","repository":{"id":47126490,"uuid":"61440286","full_name":"aviddiviner/gin-limit","owner":"aviddiviner","description":"Gin middleware to limit simultaneous requests.","archived":false,"fork":false,"pushed_at":"2017-09-18T01:28:24.000Z","size":2,"stargazers_count":112,"open_issues_count":0,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-02-14T19:32:46.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aviddiviner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-18T15:38:25.000Z","updated_at":"2024-02-06T16:08:46.000Z","dependencies_parsed_at":"2022-09-26T17:50:43.686Z","dependency_job_id":null,"html_url":"https://github.com/aviddiviner/gin-limit","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/aviddiviner%2Fgin-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aviddiviner%2Fgin-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aviddiviner%2Fgin-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aviddiviner%2Fgin-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aviddiviner","download_url":"https://codeload.github.com/aviddiviner/gin-limit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253816737,"owners_count":21968875,"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":[],"created_at":"2024-08-03T23:00:34.266Z","updated_at":"2026-01-12T02:57:46.692Z","avatar_url":"https://github.com/aviddiviner.png","language":"Go","funding_links":[],"categories":["Middlewares","Go"],"sub_categories":[],"readme":"# gin-limit\nStay under the limit with this handy Gin middleware.\n\n## Purpose\nBy default, [http.ListenAndServe](https://golang.org/pkg/net/http/#ListenAndServe) (which [gin.Run](https://github.com/gin-gonic/gin/blob/9e930b9bdd5a29bac38fb491ffac4e7ea84b825d/gin.go#L221) wraps) will serve an unbounded number of requests.  Limiting the number of simultaneous connections can sometimes greatly speed things up under load.  Inspired by [x/net/netutil.LimitListener](https://godoc.org/golang.org/x/net/netutil#LimitListener).\n\n## Example\n```go\npackage main\n\nimport (\n  \"github.com/aviddiviner/gin-limit\"\n  \"github.com/gin-gonic/gin\"\n)\n\nfunc main() {\n  r := gin.Default()\n  r.Use(limit.MaxAllowed(20))\n  // ...\n  r.Run(\":8080\")\n}\n```\n\n## Lies, damned lies and statistics\nEveryone loves synthetic benchmarks, so have some numbers from my 2015 Macbook (on a fast rendering page; single sqlite query, basic templates).\n\n    % wrk -t12 -c400 -d20s http://localhost:4560/\n    Running 20s test @ http://localhost:4560/\n      12 threads and 400 connections\n      Thread Stats   Avg      Stdev     Max   +/- Stdev\n        Latency   848.63ms  525.39ms   1.64s    62.81%\n        Req/Sec    45.43     61.85   360.00     90.50%\n      8908 requests in 20.10s, 21.91MB read\n      Socket errors: connect 0, read 219, write 0, timeout 0\n    Requests/sec:    443.19\n    Transfer/sec:      1.09MB\n\nNow 10x faster with `limit.MaxAllowed(3)` (although that would be higher in the real world).  Hooray!\n\n    % wrk -t12 -c400 -d20s http://localhost:4560/\n    Running 20s test @ http://localhost:4560/\n      12 threads and 400 connections\n      Thread Stats   Avg      Stdev     Max   +/- Stdev\n        Latency    94.40ms   32.65ms 656.72ms   86.44%\n        Req/Sec   351.61     84.32   666.00     79.32%\n      84181 requests in 20.09s, 207.05MB read\n      Socket errors: connect 0, read 165, write 0, timeout 0\n    Requests/sec:   4189.75\n    Transfer/sec:     10.30MB\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faviddiviner%2Fgin-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faviddiviner%2Fgin-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faviddiviner%2Fgin-limit/lists"}