Giter Site home page Giter Site logo

alekras / ex.rsrc_pool Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 69 KB

Resource pool is implemented in Elixir 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. Database connection is most popular example for pooling resource.

License: Apache License 2.0

Elixir 100.00%
elixir resource-pool connection-pool pool pooling pooling-utility

ex.rsrc_pool's Introduction

Resource Pool - Getting started

Summary

Resource pool (rsrc_pool_ex)project is written in Elixir 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, written in Elixir and it is using Erlang OTP design principles and Erlang concurrent model. Resource Pool is Elixir application library.

Structure

  • ResourcePool.GenServer (resource_pool_srv.ex) is a main module of Resource Pool. It is generic server and implements almost all Pool functionality.
  • ResourcePool (resource_pool.ex) is a facade for GenServer and exposes all API functions.
  • ResourceFactory (resource_factory.ex) defines ResourceFactory behaviour.

Getting started

  1. Create instance of Resource Pool
    {:ok, pid} = ResourcePool.new(:test_pool, ResourceFactory, [])
    
    where:
    • :test_pool - registered name of the new pool;
    • ResourceFactory - name of a module that implements ResourceFactory behaviour. New resource pool is usually shared between few processes.
  2. Borrow resource from pool
    resource = ResourcePool.borrow(:test_pool)
    
    The process can use the borrowed resource and has to return to pool after finish.
  3. Return resource to pool
    :ok = ResourcePool.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} = ResourcePool.new(:test_pool, ResourceFactory, options)
    
    See ResourcePool for more details about options.

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

Installation

If available in Hex, the package can be installed by adding rsrc_pool_ex to your list of dependencies in mix.exs:

def deps do
  [
    {:rsrc_pool_ex, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/rsrc_pool_ex.

ex.rsrc_pool's People

Contributors

alekras avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.