{"id":31710161,"url":"https://github.com/emqx/ecpool","last_synced_at":"2025-10-09T00:11:26.517Z","repository":{"id":45951017,"uuid":"48788262","full_name":"emqx/ecpool","owner":"emqx","description":"Erlang Connection/Client Pool Library","archived":false,"fork":false,"pushed_at":"2025-09-12T12:04:30.000Z","size":308,"stargazers_count":30,"open_issues_count":2,"forks_count":22,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-09-29T22:58:33.035Z","etag":null,"topics":["pool-worker"],"latest_commit_sha":null,"homepage":"","language":"Erlang","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/emqx.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,"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":"2015-12-30T07:27:55.000Z","updated_at":"2025-09-12T12:03:56.000Z","dependencies_parsed_at":"2023-12-05T10:27:22.185Z","dependency_job_id":"70397d64-552e-4ed0-bc8e-008f139e04a4","html_url":"https://github.com/emqx/ecpool","commit_stats":{"total_commits":66,"total_committers":15,"mean_commits":4.4,"dds":0.696969696969697,"last_synced_commit":"d01b8cb99af90bc177eeeabe29075133db878fb3"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/emqx/ecpool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2Fecpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2Fecpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2Fecpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2Fecpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emqx","download_url":"https://codeload.github.com/emqx/ecpool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2Fecpool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000745,"owners_count":26082879,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","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":["pool-worker"],"created_at":"2025-10-09T00:10:33.775Z","updated_at":"2025-10-09T00:11:26.512Z","avatar_url":"https://github.com/emqx.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Erlang Connection/Client Pool\n\n`ecpool` is different with worker-pool libraries in that it is designed to pool connection/clients to server or database.\n\n`ecpool` tries to avoid the erlang application crash when the server or database going down.\n\n## Overview\n\nA pool worker to manage/monitor the connection to server or database:\n\n```\nPoolWorker -\u003e Conn -\u003e DB\n```\n\nUse client:\n\n```\necpool:with_client(Pool, fun(Client) -\u003e call(Client) end).\n```\n\n## Usage\n\n### Start the pool\n\n```\necpool:start_pool(Pool, Mod, Opts).\n```\n\nFor example:\n\n```\nPgOpts = [%% Pool Size\n          {pool_size, 10},\n          %% Pool Type: round_robin | random | hash\n          {pool_type, round_robin},\n          %% Auto reconnect\n          {auto_reconnect, 3},\n\n          %% epgsql opts\n          {host, \"localhost\"},\n          {port, 5432},\n          {username, \"feng\"},\n          {password, \"\"},\n          {database, \"mqtt\"},\n          {encoding,  utf8}],\n\necpool:start_pool(epgsql_pool, epgsql_pool_client, PgOpts)\n```\n\n### The Callback Module\n\nPool Worker Callback:\n\n```\n-callback connect(ConnOpts :: list()) -\u003e {ok, pid()} | {error, any()}.\n```\n\nFor example, epgsql_pool_client module:\n\n```\n-module(epgsql_pool_client).\n\n-behavihour(ecpool_worker).\n\nconnect(Opts) -\u003e\n    Host = proplists:get_value(host, Opts),\n    Username = proplists:get_value(username, Opts),\n    Password = proplists:get_value(password, Opts),\n    epgsql:connect(Host, Username, Password, conn_opts(Opts)).\n\nsquery(Pool, Sql) -\u003e\n    ecpool:with_client(Pool, fun(Client) -\u003e epgsql:squery(Client, Sql) end).\n```\n\n## Design\n\nThe `ecpool` supervisor tree:\n\n```\npool_sup[one_for_all supervisor]\n    pool[gen-server]\n    worker_sup[one_for_one supervisor]\n        worker1 -\u003e connection1\n        worker2 -\u003e connection1\n        ....\n```\n\n## Author\n\nFeng Lee \u003cfeng@emqx.io\u003e\n\n## License\n\nThe Apache License Version 2.0\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femqx%2Fecpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femqx%2Fecpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femqx%2Fecpool/lists"}