Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple non intrusive resource pool for connections

License

NotificationsYou must be signed in to change notification settings

erlware/episcina

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Episcina is designed as a pool for resources. Generally thoseresources are expected to be connections to some type of externalthing like a sql system. However, there is nothing sql specific aboutepiscina. You may generally consider it a small very focused poolimplementation 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 toconnect. There are several parameters that are required.

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

Episcina also has two optional parameters:

  • max_restarts: the number of restarts that are allowedto occur withinmax_seconds_between_restarts seconds. (Default: 1000)
  • max_seconds_between_restarts: If more thanmax_restarts restartsoccur withinmax_seconds_between_restarts seconds, the episcina supervisorwill 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 calledget_connection and returns theallocated connection to the pool if that process dies.
  • If a connection dies, a new one is created and added to the pool inits place.
  • If the caller holds the pool longer the specified pool timeout thenan exit message is sent to the calling process and the connection isreturned to the pool.

[8]ページ先頭

©2009-2025 Movatter.jp