{"id":17964814,"url":"https://github.com/silviucpp/erlpool","last_synced_at":"2025-04-09T09:11:11.974Z","repository":{"id":42187824,"uuid":"84607098","full_name":"silviucpp/erlpool","owner":"silviucpp","description":"Erlang round-robin load balancer for Erlang processes based on ETS","archived":false,"fork":false,"pushed_at":"2025-03-04T14:45:56.000Z","size":46,"stargazers_count":23,"open_issues_count":0,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T03:41:51.048Z","etag":null,"topics":["erlang","pool","worker"],"latest_commit_sha":null,"homepage":null,"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/silviucpp.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}},"created_at":"2017-03-10T22:47:52.000Z","updated_at":"2025-03-04T14:45:44.000Z","dependencies_parsed_at":"2025-03-01T20:24:13.787Z","dependency_job_id":"9bb1dcb6-5aa7-481d-ad7d-b657ea07009c","html_url":"https://github.com/silviucpp/erlpool","commit_stats":{"total_commits":42,"total_committers":3,"mean_commits":14.0,"dds":"0.45238095238095233","last_synced_commit":"335b52c301239ca346a4b695760f5c4bd1acfcf8"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silviucpp%2Ferlpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silviucpp%2Ferlpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silviucpp%2Ferlpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silviucpp%2Ferlpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/silviucpp","download_url":"https://codeload.github.com/silviucpp/erlpool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008630,"owners_count":21032556,"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":["erlang","pool","worker"],"created_at":"2024-10-29T12:08:50.927Z","updated_at":"2025-04-09T09:11:11.957Z","avatar_url":"https://github.com/silviucpp.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"erlpool\n================\n\n[![Build Status](https://app.travis-ci.com/silviucpp/erlpool.svg?branch=master)](https://travis-ci.com/github/silviucpp/erlpool)\n![GitHub](https://img.shields.io/github/license/silviucpp/erlpool)\n[![Hex.pm](https://img.shields.io/hexpm/v/erlpool)](https://hex.pm/packages/erlpool)\n\nErlang round-robin load balancer for Erlang processes based on ETS\n\nWhat erlpool does\n-----------\n\nErlpool is a round-robin load balancer for Erlang processes meant mainly to be used with things like database connections. \nCompared to [pooler][3] and [poolboy][4], `erlpool` is very simple and small (~100 LOC) with no assumptions about the workers.\n\nEach time you ask for a pid the library is doing over ETS one `counter_update` operation and one `lookup`. This is inspired\nfrom [cuesport][2] which beside this is doing an additional `lookup`. This additional `lookup` in `erlpool` was transformed using \ndynamic compilation in a simple function call. Also another project from where I got inspired is [revolver][1]. \n\nQuick start\n-----------\n\nGetting all deps and compile:\n\n```sh\nrebar3 compile\n```\n\nLet's suppose you have a `gen_server` similar with the `benchmark_worker` from benchmark folder. You create a pool for this in the following way:\n\n```erlang \napplication:ensure_all_started(erlpool),\nArgs = [\n    {size, 20},\n    {start_mfa, {benchmark_worker, start_link, [WorkerArgs]}},\n    {supervisor_period, 1},\n    {supervisor_intensity, 1000},\n    {supervisor_shutdown, 5000}\n],\n\nerlpool:start_pool(pool_name, Args).\n```\n\nOr in case you want to use the `sys.config` you can use:\n\n```erlang\n[\n    {erlpool, [\n        {pools, [\n            {mypool, [\n                {size, 50},\n                {group, mygroup},\n                {start_mfa, {benchmark_worker, start_link, [ [] ]} },\n                {supervisor_period, 1},\n                {supervisor_intensity, 1000},\n                {supervisor_restart, permanent},\n                {supervisor_shutdown, 5000}\n            ]}\n        ]}\n    ]}\n].\n```\n\nArguments:\n\n- `size` : the pool size (how many workers are created and added in the supervisor)\n- `group`: used to group multiple pools in a group. For example, you have two different apps that are using erlpool and you want to restart/delete the \npools for app1. Using groups you can delete/restart all pools for a certain application. \n- `smart_mfa` : Defines the function call used to start the child process. It must be a module-function-arguments tuple `{M,F,A}` used as `apply(M,F,A)`\n- `args_include_worker_id` : Include the worker id into the arguments from `smart_mfa` as first argument.\n- `supervisor_period` : the supervisor restart period in seconds (default to 1)\n- `supervisor_intensity` : the supervisor restart intensity (defaults to 100)\n- `supervisor_restart` : the supervisor restart strategy (permanent (default) | transient | temporary)\n- `supervisor_shutdown` : defines how the worker process must be terminated  (brutal_kill | timeout()) - default 2000.\n\nIf you are not familiar with supervisor settings check the [documentation][5]. Basically to prevent a supervisor from getting \ninto an infinite loop of child process terminations and restarts, a maximum restart intensity is defined using two integer values. \nAssuming the values `supervisor_intensity` and `supervisor_period`, then, if more than `supervisor_intensity` restarts occur within \n`supervisor_period` seconds, the supervisor terminates all child processes and then itself. The intensity defaults to 100 and period defaults to 1.\n\nAPI\n-------\n\n#### Create a pool at runtime\n\n```erlang \nArgs = [\n    {size, 20},\n    {start_mfa, {benchmark_worker, start_link, [WorkerArgs]}},\n    {supervisor_period, 1},\n    {supervisor_intensity, 1000}\n],\n\nok = erlpool:start_pool(pool_name, Args).\n```\n\n#### Remove a pool at runtime\n\n```erlang\nok = erlpool:stop_pool(pool_name).\n```\n\n#### Restart a pool\n\nUse the following function when you want to restart a pool\n\n```\nok = erlpool:restart_pool(pool_name).\n```\n\n#### Get a pid from pool:\n\nTo get a pid from a pool in a round robbin fashion you are using:\n\n```erlang\nPid = erlpool:pid(pool_name).\n```\n\n#### Run a function over all pid's in a pool:\n\nIn case you want to run a function over all pid's in the pool you can use the `map/2` function. For example the following\nfunction returns all pid's in a list:\n\n```erlang\nerlpool:map(pool_name, fun(Pid) -\u003e Pid end).\n```\n\n#### Stop all pools in a group\n\nTo remove all pools in a group use: \n\n```erlang\n erlpool:stop_group(group_name).\n```\n\n#### Restart all pools in a group\n\nTo restart all pools in a group use:\n\n```erlang\n erlpool:restart_group(group_name).\n```\n\nPerformance testing\n-----------\n\nThe code is in `benchmark` folder. The test sends 100000 requests from 4000 concurrent processes to a gen_server that \nreplies with ok. The pools have 20 workers.\n\n```sh\nmake bench\n### erlpool 231 ms 500000 req/sec \n### cuesport 664 ms 166666 req/sec \n### revolver 755 ms 142857 req/sec \n### poolboy 1246 ms 83333 req/sec \n### pooler 2587 ms 40000 req/sec \n```\n\nYou can run it yourself using `make bench` \n\nRunning tests\n-----------\n\n```\nmake ct\n```\n\n[1]:https://github.com/odo/revolver\n[2]:https://github.com/esl/cuesport\n[3]:https://github.com/seth/pooler\n[4]:https://github.com/devinus/poolboy\n[5]:http://erlang.org/doc/man/supervisor.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilviucpp%2Ferlpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilviucpp%2Ferlpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilviucpp%2Ferlpool/lists"}