Menu

Tree [3fbe84] master /
 History

HTTPS access


File Date Author Commit
 .settings 2017-09-18 alekras alekras [76c403] Change project config for rebar 3.
 include 2020-06-08 alekras alekras [542baf] Update @copyright year.
 priv 2020-06-10 alekras alekras [73500e] Update Read me files.
 src 2020-06-26 alekras alekras [3fbe84] Add hex publish.
 test 2020-06-08 alekras alekras [542baf] Update @copyright year.
 .gitignore 2016-02-09 Alexei Krasnopolski Alexei Krasnopolski [e2f694] initial commit
 .project 2016-02-09 Alexei Krasnopolski Alexei Krasnopolski [e2f694] initial commit
 LICENSE 2016-02-09 alekras alekras [d243a5] Initial commit
 README.md 2020-06-26 alekras alekras [3fbe84] Add hex publish.
 archive.xml 2020-05-18 alekras alekras [b86418] Refactoring code.
 article.md 2020-06-10 alekras alekras [8be37a] Update article format.
 rebar.config 2020-06-26 alekras alekras [3fbe84] Add hex publish.

Read Me

Resource Pool (rsrc_pool)

Resource pool project is written in Erlang as a tiny library. The goal of the tool is reduce the overhead of creating new resources by reusing of the same resources among multiple processes. Achieving result is better performance and throughput. The resource pool was inspired by Java Apache's commons pool and adopts API and main principals from this project. Database connection is most popular example for pooling resource.

Introduction

Resource pool project was inspired by Apache Commons Pool library and API was borrowed from there. But internal
implementation is completely different and is using Erlang OTP design principles and Erlang concurrent model. Resource Pool
is Erlang application library.

Structure

  • resource_pool_srv.erl is a main module of Resource Pool. It is generic server and implements almost all Pool functionality.
  • resource_pool.erl is a facade for gen_server and exposes all API functions.
  • resource_factory.erl defines resource_factory behaviour and acts as a template and simple implementation resource factory for testing purpose.

Getting started

  1. Create instance of Resource Pool
    {ok, Pid} = resource_pool:new(test_pool, resource_factory, [])
    where:
    • test_pool - registered name of the new pool;
    • resource_factory - name of a module that implements resource_factory behaviour.
    New resource pool is usually shared between few processes.
  2. Borrow resource from pool
    Resource = resource_pool:borrow(test_pool)
    The process can use the borrowed resource and has to return to pool after finish.
  3. Return resource to pool
    ok = resource_pool:return(test_pool, Resource)
    The process cannot use the Resource anymore.
  4. Pool can be created with options:
    Options = [{max_active, 10}, {when_exhausted_action, fail}]
    {ok, Pid} = resource_pool:new(test_pool, resource_factory, Options)
    See resource_pool for more details about options.

See Resource Pool article for details and http://erlpool.sourceforge.net/.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.