GithubHelp home page GithubHelp logo

edwardt / episcina Goto Github PK

View Code? Open in Web Editor NEW

This project forked from erlware/episcina

0.0 3.0 0.0 304 KB

A simple non intrusive resource pool for connections

License: Other

Makefile 10.84% Erlang 89.16%

episcina's Introduction

Episcina - A Simple Erlang Connection Pool

Episcina is designed as a pool for resources. Generally those resources are expected to be connections to some type of external thing like a sql system. However, there is nothing sql specific about episcina. You may generally consider it a small very focused pool implementation that does not try to take ownership of your work.

How It Works

Episcina will create any pools defined in the episcina's 'pools' environment parameter, which is a proplist that tells episcina how to connect. There are several parameters that are required.

  • size - The maximum size of the pool
  • timeout - The maximum number of milliseconds that the a caller is allowed to hold a connection. See below for the consequences of holding a connection open too long.
  • connect_provider - This is the function + arguments that will be used to provide connections. It contains the name of the module, the name of the function and the arguments to pass to that function. There is an example below.
  • close_provider - This is tthe function + arguments that will be used to close connections. It contains the name of the module, the name of the function and any arguments needed to be passed to that function. There is an example below.

Episcina also has two optional parameters:

  • max_restarts: the number of restarts that are allowed to occur within max_seconds_between_restarts seconds. (Default: 1000)
  • max_seconds_between_restarts: If more than max_restarts restarts occur within max_seconds_between_restarts seconds, the episcina supervisor will terminate all its child processes, then itself. (Default: 3600)

sys.config file example:

{episcina, [{max_restarts, 2000},
            {max_seconds_between_restarts, 7200},
            {pools, [{db1,
                          [{size, 10},
                           {timeout, 10000},
                           {connect_provider, {pgsql, connect,
                                               ["localhost",
                                                5432,
                                                "my supersecret pass",
                                                "postgresql",
                                                [{database, "foobar"}]]}},
                           {close_provider, {pgsql, close, []}}]}]}]}.

Pool Usage

{ok, C} = episcina:get_connection(Pool, Timeout).
  • Pool - Name of pool.
  • Timeout - Time, in milliseconds, to wait for a free connection.
ok = episcina:return_connection(Pool, Connection).

Details

  • Episcina monitors the process which called get_connection and returns the allocated connection to the pool if that process dies.
  • If a connection dies, a new one is created and added to the pool in its place.
  • If the caller holds the pool longer the specified pool timeout then an exit message is sent to the calling process and the connection is returned to the pool.

episcina's People

Contributors

ericbmerritt avatar jwilberding avatar tsloughter avatar catamorphism avatar omarkj avatar ferd avatar waisbrot avatar vaxelfel avatar

Watchers

edwardt avatar James Cloos 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.