{"id":48680713,"url":"https://github.com/jabley/rate-limit","last_synced_at":"2026-04-26T20:00:41.820Z","repository":{"id":555938,"uuid":"186640","full_name":"jabley/rate-limit","owner":"jabley","description":"Java Rate-Limiting API","archived":false,"fork":false,"pushed_at":"2018-03-02T09:23:56.000Z","size":97,"stargazers_count":61,"open_issues_count":2,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-10-10T19:25:50.703Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jabley.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":"2009-04-27T12:09:46.000Z","updated_at":"2025-08-23T12:28:16.000Z","dependencies_parsed_at":"2022-07-07T14:20:54.630Z","dependency_job_id":null,"html_url":"https://github.com/jabley/rate-limit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jabley/rate-limit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabley%2Frate-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabley%2Frate-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabley%2Frate-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabley%2Frate-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jabley","download_url":"https://codeload.github.com/jabley/rate-limit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabley%2Frate-limit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32310804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T19:15:34.056Z","status":"ssl_error","status_checked_at":"2026-04-26T19:15:15.467Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-04-11T01:00:36.056Z","updated_at":"2026-04-26T20:00:41.811Z","avatar_url":"https://github.com/jabley.png","language":"Java","funding_links":[],"categories":["容错组件"],"sub_categories":["Spring Cloud框架"],"readme":"# Overview\n\nContains the primitives and utilities used to rate-limit / throttle Java \napplications, and a CircuitBreaker implementation.\n\n# Summary\nInspired by reading Cal Henderson's \"Building Scalable Web Sites\" which talks \nbriefly about this, and having been on the receiving end of a kicking from \nsearch engines, I wanted to have a simple way of determining whether to bother\nprocessing requests and stop consuming server resources in a graceful way, \nrather than grinding to a halt.\n\n## Background - types of throttling\n\n### Next Service Slot\n\nEach time a request comes in, we log the time. If it hasn't been a certain \nduration since the last request, then abort with a rate-limiting error.\n\n    key = create_key(request)\n    \n    entry = gate.get_entry(key)\n\n    if (entry)\n        response.set_status(SERVICE_UNAVAILABLE)\n        return\n    end\n    \n    entry = create_entry(expires =\u003e '5s')\n    \n    gate.put_entry(key, entry)\n    \n    ...\n\n\n### Fixed Bucket\n\nWe define a duration and an acceptable number of requests to be serviced in \nthat time. Each time a request comes in, we look up the number of calls made \nin the current period. If it is at or above the limit, then abort with a \nrate-limiting error, otherwise increment the counter and service the request.\n\n    key = create_key(request)\n    \n    entry = gate.get_entry(key)\n    \n    if (entry.count \u003e= ALLOWED_PER_PERIOD)\n        response.set_status(SERVICE_UNAVAILABLE)\n        return\n    end\n\n    entry.count.increment()\n    \n    ...\n\nFrom this description, it can be seen that Next Service Slot is essentially \nFixed Bucket with a max size of 1 and an appropriate service period.\n\n### Leaky Bucket\n\nSimilar to a Fixed Bucket, except that rather than aborting, we block until \nthe end of the current time period upon which the bucket counter is \ndecremented / completely emptied and then we service the request.\n\nHardest to implement, has the disadvantage that it will tie up a \nrequest-handling thread (which may cause upstream services to timeout / retry) \nbut may be a good solution in other contexts.\n\n    key = create_key(request)\n    \n    entry = gate.get_entry(key)\n    \n    if (entry.count \u003e= ALLOWED_PER_PERIOD)\n        entry.wait()\n    end\n\n    entry.count.increment()\n    \n    ...\n\n## CircuitBreaker\n\nThere is some overlap in the intention of this library with the Circuit Breaker \napproach described by Michael Nygard in his excellent book \"Release It!\"; I've\ndone some work to add support for that as well. We've been running it in\nproduction for a year and it works well for our purposes.\n\nPlease see the tests for details as to how to use it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjabley%2Frate-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjabley%2Frate-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjabley%2Frate-limit/lists"}