{"id":17632399,"url":"https://github.com/bohde/codel","last_synced_at":"2025-05-05T21:11:08.055Z","repository":{"id":55817633,"uuid":"163595807","full_name":"bohde/codel","owner":"bohde","description":"Go implementation of the Controlled Delay algorithm","archived":false,"fork":false,"pushed_at":"2025-02-18T23:32:38.000Z","size":43,"stargazers_count":33,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T23:41:15.359Z","etag":null,"topics":["concurrency","concurrent-queues","queue-management","rate-limiting"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bohde.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-30T15:04:24.000Z","updated_at":"2025-02-19T22:33:21.000Z","dependencies_parsed_at":"2025-03-10T00:32:18.227Z","dependency_job_id":"370fbeda-24a6-4acc-9ded-0449d0dbb7bb","html_url":"https://github.com/bohde/codel","commit_stats":null,"previous_names":["bohde/codel","joshbohde/codel"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohde%2Fcodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohde%2Fcodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohde%2Fcodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohde%2Fcodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bohde","download_url":"https://codeload.github.com/bohde/codel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252577020,"owners_count":21770721,"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":["concurrency","concurrent-queues","queue-management","rate-limiting"],"created_at":"2024-10-23T01:07:09.585Z","updated_at":"2025-05-05T21:11:08.037Z","avatar_url":"https://github.com/bohde.png","language":"Go","readme":"# codel\n\n[![GoDoc](https://pkg.go.dev/github.com/bohde/codel?status.svg)](https://pkg.go.dev/github.com/bohde/codel)\n\n`codel` implements the [Controlled Delay](https://queue.acm.org/detail.cfm?id=2209336) algorithm for overload detection, providing a mechanism to shed load when overloaded. It optimizes for latency while keeping throughput high, even when downstream rates dynamically change.\n\n`codel` keeps latency low when even severely overloaded, by preemptively shedding some load when wait latency is long. It is comparable to using a queue to handle bursts of load, but improves upon this technique by avoiding the latency required to handle all previous entries in the queue.\n\nIn a simulation of 1000 reqs/sec incoming, 500 reqs/sec outgoing averages for 10 seconds, here's the corresponding throughput and latency profile of both a queue and `codel`. Throughput is slightly higher than the average due to randomness in the simulation.\n\n| method | throughput | p50          | p95          | p99          |\n|--------|------------|--------------|--------------|--------------|\n| queue  | 507.41     | 963.604953ms | 1.024595796s | 1.041455537s |\n| codel  | 513.17     | 27.718827ms  | 44.085795ms  | 62.756499ms  |\n\n\nSource code for the simulations are included in the [sim directory](cmd/sim).\n\n## Installation\n\n```\n$ go get github.com/bohde/codel\n```\n\n## Example\n\n```\nimport (\n    \"context\"\n    \"github.com/bohde/codel\"\n)\n\nfunc Example() {\n\tc := codel.New(codel.Options{\n\t\t// The maximum number of pending acquires\n\t\tMaxPending: 100,\n\t\t// The maximum number of concurrent acquires\n\t\tMaxOutstanding: 10,\n\t\t// The target latency to wait for an acquire.\n\t\t// Acquires that take longer than this can fail.\n\t\tTargetLatency: 5 * time.Millisecond,\n\t})\n\n\t// Attempt to acquire the lock.\n\terr := c.Acquire(context.Background())\n\n\t// if err is not nil, acquisition failed.\n\tif err != nil {\n\t\treturn\n\t}\n\n\t// If acquisition succeeded, we need to release it.\n\tdefer c.Release()\n\n\t// Do some process with external resources\n}\n\n```\n\n## Benchmarks\n\nThe `Lock` serializes access, introducing latency overhead. When not overloaded, this overhead should be under 1us.\n\n```\nBenchmarkLockUnblocked-4        20000000                73.1 ns/op             0 B/op          0 allocs/op\nBenchmarkLockBlocked-4           2000000               665 ns/op             176 B/op          2 allocs/op\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbohde%2Fcodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbohde%2Fcodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbohde%2Fcodel/lists"}