All Projects → devinus → Poolboy

devinus / Poolboy

Licence: other
A hunky Erlang worker pool factory

Programming Languages

erlang
1774 projects

Labels

Projects that are alternatives of or similar to Poolboy

Pool
🚌 A golang general network connection poolction pool
Stars: ✭ 588 (-56.86%)
Mutual labels:  pool
Gorpool
Simple Goroutine pool
Stars: ✭ 37 (-97.29%)
Mutual labels:  pool
Cekirdekler
Multi-device OpenCL kernel load balancer and pipeliner API for C#. Uses shared-distributed memory model to keep GPUs updated fast while using same kernel on all devices(for simplicity).
Stars: ✭ 76 (-94.42%)
Mutual labels:  pool
Grpool
Lightweight Goroutine pool
Stars: ✭ 616 (-54.81%)
Mutual labels:  pool
Go Extend
go语言扩展包,收集一些常用的操作函数,辅助更快的完成开发工作,并减少重复代码
Stars: ✭ 839 (-38.44%)
Mutual labels:  pool
Open Ethereum Pool
Open Ethereum Mining Pool
Stars: ✭ 1,062 (-22.08%)
Mutual labels:  pool
Groupco
PHP的服务化框架。适用于Api、Http Server、Rpc Server;帮助原生PHP项目转向微服务化。出色的性能与支持高并发的协程相结合
Stars: ✭ 473 (-65.3%)
Mutual labels:  pool
Earl
Service Objects for Crystal (Agents, Artists, Supervisors, Pools, ...)
Stars: ✭ 89 (-93.47%)
Mutual labels:  pool
Errand Boy
A memory-conscious alternative to os.fork() and subprocess.Popen().
Stars: ✭ 34 (-97.51%)
Mutual labels:  pool
Cv4pve Barc
Backup And Restore Ceph for Proxmox VE
Stars: ✭ 74 (-94.57%)
Mutual labels:  pool
Coiniumserv
Next-gen crypto currency mining pool software
Stars: ✭ 651 (-52.24%)
Mutual labels:  pool
Oeasypool
c++11 thread pool
Stars: ✭ 18 (-98.68%)
Mutual labels:  pool
Cardano Node Docker
Docker container for setting up and running a Cardano Stake Pool
Stars: ✭ 68 (-95.01%)
Mutual labels:  pool
Ants
🐜🐜🐜 ants is a high-performance and low-cost goroutine pool in Go, inspired by fasthttp./ ants 是一个高性能且低损耗的 goroutine 池。
Stars: ✭ 7,180 (+426.78%)
Mutual labels:  pool
Ycsocket
基于swoole的socket框架,支持协程版MySQL、Redis连接池,已用于大型RPG游戏服务端
Stars: ✭ 77 (-94.35%)
Mutual labels:  pool
Btcpool Abandoned
backend of pool.btc.com
Stars: ✭ 541 (-60.31%)
Mutual labels:  pool
Lite Pool
A lite fast object pool
Stars: ✭ 42 (-96.92%)
Mutual labels:  pool
Pool
General Purpose Connection Pool for GRPC,RPC,TCP Sevice Cluster
Stars: ✭ 98 (-92.81%)
Mutual labels:  pool
Nplusminer
NPlusMiner + GUI | NVIDIA/AMD/CPU miner | AI | Autoupdate | MultiRig remote management
Stars: ✭ 75 (-94.5%)
Mutual labels:  pool
Pool
Connection pool for Go's net.Conn interface
Stars: ✭ 1,174 (-13.87%)
Mutual labels:  pool

Poolboy - A hunky Erlang worker pool factory

Build Status

Support via Gratipay

Poolboy is a lightweight, generic pooling library for Erlang with a focus on simplicity, performance, and rock-solid disaster recovery.

Usage

1> Worker = poolboy:checkout(PoolName).
<0.9001.0>
2> gen_server:call(Worker, Request).
ok
3> poolboy:checkin(PoolName, Worker).
ok

Example

This is an example application showcasing database connection pools using Poolboy and epgsql.

example.app

{application, example, [
    {description, "An example application"},
    {vsn, "0.1"},
    {applications, [kernel, stdlib, sasl, crypto, ssl]},
    {modules, [example, example_worker]},
    {registered, [example]},
    {mod, {example, []}},
    {env, [
        {pools, [
            {pool1, [
                {size, 10},
                {max_overflow, 20}
			], [
                {hostname, "127.0.0.1"},
                {database, "db1"},
                {username, "db1"},
                {password, "abc123"}
            ]},
            {pool2, [
                {size, 5},
                {max_overflow, 10}
			], [
                {hostname, "127.0.0.1"},
                {database, "db2"},
                {username, "db2"},
                {password, "abc123"}
            ]}
        ]}
    ]}
]}.

example.erl

-module(example).
-behaviour(application).
-behaviour(supervisor).

-export([start/0, stop/0, squery/2, equery/3]).
-export([start/2, stop/1]).
-export([init/1]).

start() ->
    application:start(?MODULE).

stop() ->
    application:stop(?MODULE).

start(_Type, _Args) ->
    supervisor:start_link({local, example_sup}, ?MODULE, []).

stop(_State) ->
    ok.

init([]) ->
    {ok, Pools} = application:get_env(example, pools),
    PoolSpecs = lists:map(fun({Name, SizeArgs, WorkerArgs}) ->
        PoolArgs = [{name, {local, Name}},
            		{worker_module, example_worker}] ++ SizeArgs,
        poolboy:child_spec(Name, PoolArgs, WorkerArgs)
    end, Pools),
    {ok, {{one_for_one, 10, 10}, PoolSpecs}}.

squery(PoolName, Sql) ->
    poolboy:transaction(PoolName, fun(Worker) ->
        gen_server:call(Worker, {squery, Sql})
    end).

equery(PoolName, Stmt, Params) ->
    poolboy:transaction(PoolName, fun(Worker) ->
        gen_server:call(Worker, {equery, Stmt, Params})
    end).

example_worker.erl

-module(example_worker).
-behaviour(gen_server).
-behaviour(poolboy_worker).

-export([start_link/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
         code_change/3]).

-record(state, {conn}).

start_link(Args) ->
    gen_server:start_link(?MODULE, Args, []).

init(Args) ->
    process_flag(trap_exit, true),
    Hostname = proplists:get_value(hostname, Args),
    Database = proplists:get_value(database, Args),
    Username = proplists:get_value(username, Args),
    Password = proplists:get_value(password, Args),
    {ok, Conn} = epgsql:connect(Hostname, Username, Password, [
        {database, Database}
    ]),
    {ok, #state{conn=Conn}}.

handle_call({squery, Sql}, _From, #state{conn=Conn}=State) ->
    {reply, epgsql:squery(Conn, Sql), State};
handle_call({equery, Stmt, Params}, _From, #state{conn=Conn}=State) ->
    {reply, epgsql:equery(Conn, Stmt, Params), State};
handle_call(_Request, _From, State) ->
    {reply, ok, State}.

handle_cast(_Msg, State) ->
    {noreply, State}.

handle_info(_Info, State) ->
    {noreply, State}.

terminate(_Reason, #state{conn=Conn}) ->
    ok = epgsql:close(Conn),
    ok.

code_change(_OldVsn, State, _Extra) ->
    {ok, State}.

Options

  • name: the pool name
  • worker_module: the module that represents the workers
  • size: maximum pool size
  • max_overflow: maximum number of workers created if pool is empty
  • strategy: lifo or fifo, determines whether checked in workers should be placed first or last in the line of available workers. So, lifo operates like a traditional stack; fifo like a queue. Default is lifo.

Authors

License

Poolboy is available in the public domain (see UNLICENSE). Poolboy is also optionally available under the ISC license (see LICENSE), meant especially for jurisdictions that do not recognize public domain works.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].