{"id":44800615,"url":"https://github.com/mtingers/dflockd","last_synced_at":"2026-04-28T06:01:07.462Z","repository":{"id":337161048,"uuid":"1152535314","full_name":"mtingers/dflockd","owner":"mtingers","description":"A lightweight distributed lock server with FIFO ordering, automatic lease expiry, semaphores, and pub/sub signals. Single Go binary, zero dependencies.","archived":false,"fork":false,"pushed_at":"2026-04-25T14:02:10.000Z","size":1580,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-25T14:15:25.568Z","etag":null,"topics":["distributed-systems","fifo","locking"],"latest_commit_sha":null,"homepage":"https://mtingers.github.io/dflockd/","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/mtingers.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-08T02:41:44.000Z","updated_at":"2026-04-25T12:26:51.000Z","dependencies_parsed_at":"2026-02-16T14:01:44.646Z","dependency_job_id":null,"html_url":"https://github.com/mtingers/dflockd","commit_stats":null,"previous_names":["mtingers/dflockd"],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/mtingers/dflockd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtingers%2Fdflockd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtingers%2Fdflockd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtingers%2Fdflockd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtingers%2Fdflockd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtingers","download_url":"https://codeload.github.com/mtingers/dflockd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtingers%2Fdflockd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32368534,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"online","status_checked_at":"2026-04-28T02:00:07.250Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["distributed-systems","fifo","locking"],"created_at":"2026-02-16T13:17:22.922Z","updated_at":"2026-04-28T06:01:07.371Z","avatar_url":"https://github.com/mtingers.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dflockd\n\nA lightweight distributed lock server with FIFO ordering, automatic lease expiry, semaphores, and pub/sub signals. Speaks both a line-based TCP protocol and an optional HTTP REST + SSE API on top of the same shared state. Single Go binary, zero dependencies.\n\n[Documentation](https://mtingers.github.io/dflockd/) · [HTTP API](https://mtingers.github.io/dflockd/http-api/) · [Changelog](https://mtingers.github.io/dflockd/changelog/)\n\n## Build \u0026 run\n\n```bash\ngo build -o dflockd ./cmd/dflockd\n./dflockd  # listens on 127.0.0.1:6388\n```\n\nOr install directly:\n\n```bash\ngo install github.com/mtingers/dflockd/cmd/dflockd@latest\n```\n\n## Usage\n\n### Go\n\n```go\nimport \"github.com/mtingers/dflockd/client\"\n\nl := \u0026client.Lock{\n    Key:            \"my-resource\",\n    AcquireTimeout: 10 * time.Second,\n    Servers:        []string{\"127.0.0.1:6388\"},\n}\nok, err := l.Acquire(context.Background())\nif err != nil || !ok { /* handle */ }\ndefer l.Release(context.Background())\n```\n\nSee the [Go client reference](https://mtingers.github.io/dflockd/client/) for the full API (renewal, sharding, TLS, auth, SSE signal subscriptions).\n\n### HTTP\n\nStart the server with `--http-port 6389` to enable the optional REST + SSE layer, then:\n\n```bash\nsid=$(curl -sX POST http://localhost:6389/v1/sessions | jq -r .session_id)\ncurl -sX POST http://localhost:6389/v1/locks/my-job \\\n     -H \"X-Dflockd-Session: $sid\" \\\n     -d '{\"acquire_timeout_s\": 10, \"lease_ttl_s\": 60}'\n# → {\"status\":\"ok\",\"token\":\"...\",\"lease_ttl_s\":60}\ncurl -sX DELETE http://localhost:6389/v1/sessions/$sid\n```\n\nSee the [HTTP API docs](https://mtingers.github.io/dflockd/http-api/) and [OpenAPI spec](https://mtingers.github.io/dflockd/openapi.json).\n\n### Raw TCP protocol\n\nThe wire format is three newline-terminated UTF-8 lines (`command\\nkey\\narg\\n`). Useful for debugging or minimal-footprint clients in languages without a ready-made library:\n\n```bash\n$ nc localhost 6388\nl\nmy-key\n10\nok abc123... 33\nr\nmy-key\nabc123...\nok\n```\n\nThe connection must stay open — by default, locks are auto-released on disconnect. See the [protocol reference](https://mtingers.github.io/dflockd/architecture/protocol/) for all commands.\n\n## Performance\n\nEach operation is one lock acquire + release over a persistent TCP connection. Median of three runs on v1.16.0; Apple M1 (MacBook Air, 8 GB RAM) with server and clients on localhost.\n\n| Workers | Rounds | Ops | Throughput | Mean | p50 | p99 |\n|---|---|---|---|---|---|---|\n| 1 | 1,000 | 1,000 | 13,440 ops/s | 0.074 ms | 0.062 ms | 0.178 ms |\n| 10 | 1,000 | 10,000 | 45,861 ops/s | 0.217 ms | 0.215 ms | 0.382 ms |\n| 50 | 1,000 | 50,000 | 83,516 ops/s | 0.590 ms | 0.513 ms | 2.096 ms |\n| 100 | 1,000 | 100,000 | 87,448 ops/s | 1.124 ms | 0.935 ms | 4.192 ms |\n| 200 | 1,000 | 200,000 | 89,706 ops/s | 2.200 ms | 1.864 ms | 7.892 ms |\n| 500 | 1,000 | 500,000 | 85,124 ops/s | 5.814 ms | 5.117 ms | 18.554 ms |\n\nAll workers use unique keys (no contention). Run your own benchmarks with `go run ./cmd/bench --help`.\n\n## Configuration\n\nCLI flags take precedence over environment variables.\n\n| Flag | Env var | Default | Description |\n|---|---|---|---|\n| `--host` | `DFLOCKD_HOST` | `127.0.0.1` | Bind address |\n| `--port` | `DFLOCKD_PORT` | `6388` | Bind port |\n| `--default-lease-ttl` | `DFLOCKD_DEFAULT_LEASE_TTL_S` | `33` | Default lease duration (seconds) |\n| `--max-locks` | `DFLOCKD_MAX_LOCKS` | `1024` | Max unique lock+semaphore keys |\n| `--max-connections` | `DFLOCKD_MAX_CONNECTIONS` | `0` | Max concurrent connections (0 = unlimited) |\n| `--max-connections-per-ip` | `DFLOCKD_MAX_CONNECTIONS_PER_IP` | `0` | Max concurrent TCP connections per remote IP (0 = unlimited) |\n| `--max-waiters` | `DFLOCKD_MAX_WAITERS` | `0` | Max waiters per key (0 = unlimited) |\n| `--max-subscriptions` | `DFLOCKD_MAX_SUBSCRIPTIONS` | `0` | Max signal subscriptions per connection (0 = unlimited) |\n| `--read-timeout` | `DFLOCKD_READ_TIMEOUT_S` | `23` | Client read timeout (seconds) |\n| `--write-timeout` | `DFLOCKD_WRITE_TIMEOUT_S` | `5` | Client write timeout (seconds) |\n| `--shutdown-timeout` | `DFLOCKD_SHUTDOWN_TIMEOUT_S` | `30` | Graceful shutdown timeout (seconds, 0 = wait forever) |\n| `--tls-cert` | `DFLOCKD_TLS_CERT` | *(unset)* | TLS certificate PEM file |\n| `--tls-key` | `DFLOCKD_TLS_KEY` | *(unset)* | TLS private key PEM file |\n| `--auth-token` | `DFLOCKD_AUTH_TOKEN` | *(unset)* | Shared secret for authentication |\n| `--auth-token-file` | `DFLOCKD_AUTH_TOKEN_FILE` | *(unset)* | File containing the auth token |\n| `--auto-release-on-disconnect` | `DFLOCKD_AUTO_RELEASE_ON_DISCONNECT` | `true` | Release held locks/semaphore slots on disconnect |\n| `--http-port` | `DFLOCKD_HTTP_PORT` | `0` | HTTP API port (0 = disabled) |\n| `--http-host` | `DFLOCKD_HTTP_HOST` | same as `--host` | HTTP API bind address |\n| `--http-session-idle-timeout` | `DFLOCKD_HTTP_SESSION_IDLE_S` | `20` | HTTP session idle timeout (seconds) |\n| `--http-max-sessions` | `DFLOCKD_HTTP_MAX_SESSIONS` | `0` | Max concurrent HTTP sessions (0 = unlimited) |\n| `--http-max-sessions-per-ip` | `DFLOCKD_HTTP_MAX_SESSIONS_PER_IP` | `0` | Max concurrent HTTP sessions per remote IP (0 = unlimited) |\n| `--http-max-connections-per-ip` | `DFLOCKD_HTTP_MAX_CONNECTIONS_PER_IP` | `0` | Max concurrent HTTP transport connections per remote IP (0 = unlimited) |\n| `--http-rate-limit-per-ip` | `DFLOCKD_HTTP_RATE_LIMIT_PER_IP` | `0` | HTTP requests per second per remote IP (0 = unlimited) |\n| `--http-rate-limit-burst` | `DFLOCKD_HTTP_RATE_LIMIT_BURST` | `0` | HTTP per-IP burst size (0 = same as rate when rate is set) |\n| `--http-cors-allowed-origins` | `DFLOCKD_HTTP_CORS_ALLOWED_ORIGINS` | *(unset)* | Comma-separated CORS origins; `*` allows any origin |\n| `--http-sse-ping-interval` | `DFLOCKD_HTTP_SSE_PING_S` | `15` | Internal pinger interval for SSE streams (seconds) |\n| `--debug` | `DFLOCKD_DEBUG` | `false` | Enable debug logging |\n\nSee the [server docs](https://mtingers.github.io/dflockd/server/) for GC tuning, TLS setup, authentication, and other advanced options.\n\n## Client libraries\n\n- **Go** (in-repo) — `go get github.com/mtingers/dflockd/client` ([docs](https://mtingers.github.io/dflockd/client/))\n- **Python** — [dflockd-client-py](https://github.com/mtingers/dflockd-client-py) ([docs](https://mtingers.github.io/dflockd-client-py/))\n- **TypeScript** — [dflockd-client-ts](https://github.com/mtingers/dflockd-client-ts) ([docs](https://mtingers.github.io/dflockd-client-ts/))\n\n## Tests\n\n```bash\ngo test ./... -v\n```\n\n## Benchmarking\n\n```bash\ngo run ./cmd/bench --workers 100 --rounds 500\n```\n\nSee `go run ./cmd/bench --help` for all options.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtingers%2Fdflockd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtingers%2Fdflockd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtingers%2Fdflockd/lists"}